get_unique_ips.pl

来自「radius协议源码÷The Radius Stack will connect」· PL 代码 · 共 53 行

PL
53
字号
#!/usr/bin/perl -wuse strict;use Data::Dumper;use constant DEBUG => 1;my %IPs;my $octet = '(\d){1,3}';my $combo = "($octet\\.$octet\\.$octet\\.$octet:\\d+)"; #IP:port#The only IP:port combos we want are the ones that are actually used#as endpoints, as determined on the IP layer.  (Spurious and irrevelant combos#can appear in the headers, for esoteric reasons.)#ipgrab prints the combos it finds by actually inspecting the IP layer#in this format:  [source_ip:source_port->destination_ip:destination_port].#Hence any combo truly used will either start or end with a square bracket.#!my $IP_address_regex = qr{[$combo|$combo]};my $IP_address_regex = qr{\[$combo};#because File::Find does not work as documentedmy $find_command = "find @ARGV -type f";print "Running find command $find_command\n" if DEBUG;open (FILES, "$find_command |")    or die "Could not run find command $find_command:  $!";while (<FILES>){    chomp;    &get_IPs ($_);}print Data::Dumper->Dump ([ \%IPs ], [ 'server_map' ]);sub get_IPs{    my $filename = shift();    print "Examining file $filename...\n" if DEBUG;    if (! sysopen (FILE, $filename, 0))    {	warn "Could not open file $filename";	return;    }    while (<FILE>)    {	my @matches;	print "Next line...\n" if (DEBUG == 2);	while (m/\G$IP_address_regex/g)	{	    print "Got match $1\n" if DEBUG;	    push @matches, $1;	    map { $IPs{$_} = '' unless exists $IPs{$_}; } @matches;	}    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?