⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 host_quickie.pl

📁 radius协议源码÷The Radius Stack will connect to a Radius Server. This stack implementation is built upo
💻 PL
字号:
#!/usr/bin/perl -w# ====================================================================# The Vovida Software License, Version 1.0 # # Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved.# # Redistribution and use in source and binary forms, with or without# modification, are permitted provided that the following conditions# are met:# # 1. Redistributions of source code must retain the above copyright#    notice, this list of conditions and the following disclaimer.# # 2. Redistributions in binary form must reproduce the above copyright#    notice, this list of conditions and the following disclaimer in#    the documentation and/or other materials provided with the#    distribution.# # 3. The names "VOCAL", "Vovida Open Communication Application Library",#    and "Vovida Open Communication Application Library (VOCAL)" must#    not be used to endorse or promote products derived from this#    software without prior written permission. For written#    permission, please contact vocal@vovida.org.# # 4. Products derived from this software may not be called "VOCAL", nor#    may "VOCAL" appear in their name, without prior written#    permission of Vovida Networks, Inc.# # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND# NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA# NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES# IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH# DAMAGE.# # ====================================================================# # This software consists of voluntary contributions made by Vovida# Networks, Inc. and many individuals on behalf of Vovida Networks,# Inc.  For more information on Vovida Networks, Inc., please see# <http://www.vovida.org/>.use strict;use Data::Dumper;use constant DEBUG => 2;my %server_map;my $server_map_path = 'server_map.pl';my $dns_path        = '/root/Tricorder/tools/dns';my $octet = '(\d){1,3}';my $ip_regex = qr|(($octet\.$octet\.$octet)\.$octet):\d+|;my $server_map_code;open SERVER_MAP, $server_map_path    or die "Could not open server map $server_map_path:  $!";while (<SERVER_MAP>){   $server_map_code .= $_; }eval $server_map_code;#!require $server_map_path; #!Why doesn't this work?print "Got server map:\n" . Data::Dumper->Dump ([ \%server_map ]) if (DEBUG == 3);my @domain_files = `find $dns_path/domains -type f`;map { chomp; } @domain_files;print Data::Dumper->Dump ([ \@domain_files ], [ 'domain_files' ]);foreach (keys %server_map){    my $tuple = $_;    print "Examining tuple $tuple\n" if (DEBUG == 2);    unless (m/$ip_regex/)    {	warn "Could not parse IP:port tuple";	next;    }    my $ip     = $1; #ignore the port; DNS knows nothing about it    my $subnet = $2;    print "Examining ip $ip (subnet $subnet)...\n" if DEBUG;    $server_map{$tuple} = &look_up_cnames ($ip, $subnet);}#Write out the newly filled-in server map to a new file.my $results_file = "$server_map_path.filled-in";open RESULTS_FILE, ">$results_file"    or die "Could not write results to $results_file:  $!";#!print RESULTS_FILE Data::Dumper->Dump ([ \%server_map ], [ 'server_map' ]);print Data::Dumper->Dump ([ \%server_map ], [ 'server_map' ]);#Fill in each entry in the server map with the corresponding IP's CNAMEs.sub look_up_cnames{    my ($ip, $subnet) = @_;    my @cnames = ();    my $aname;    #grep all the files for the A name, which we need...    my $aname_regex = qr|^(\w+)\s+IN\s+A\s+$ip|;    my $domain_file;    #Can't use foreach here; the iterator is not reset correctly if    #you exit the loop with last!#!    {#!	local $_; #very important to keep from munging $_ for the caller...        #!FILE:  foreach (@domain_files)        FILE:  for (my $i = 0; $i <= $#domain_files; $i++)	{	    $domain_file = $domain_files[$i];	    print "\tLooking in domain file $domain_file\n" if (DEBUG == 2);	    open DOMAIN_FILE, $domain_file		or die "Could not open domain file $domain_file:  $!";	    	    while (<DOMAIN_FILE>) #! Could use globbing here...	    {		if (m/$aname_regex/)		{		    $aname = $1;		    print "\tFound A name:  $aname in file $domain_file\n" if DEBUG;		    last FILE;		}	    }	}#!    }    if ($aname)    {	#... to find all the CNAMEs, by taking the domain file where	#the A name was found and searching it again from the beginning...	#!seek DOMAIN_FILE, 0, 0; Why doesn't this work?	close DOMAIN_FILE;	open DOMAIN_FILE, $domain_file	    or die "Could not re-open $domain_file to look for CNAMEs (possible race condition):  $!";	my $cname_regex = qr|^(\w+)\s+IN\s+CNAME\s+$aname|;	print "\tChecking it for CNAMEs...\n" if DEBUG; 	while (<DOMAIN_FILE>)	{	    print "\tchunk $_\n" if (DEBUG == 3);	    if (m/$cname_regex/)	    {		my $cname = $1;		print "\tFound CNAME $cname\n" if DEBUG; 		push @cnames, $cname;	    }	}	close DOMAIN_FILE;    }    else    {	print "\tCould not find A name\n" if DEBUG;    }    return \@cnames; #may still be empty}

⌨️ 快捷键说明

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