#!/usr/local/bin/perl # This script takes as input the following files acthost, ARPdump, ouiresolve, and dnsdump. # The script outputs three files with names VLAN_ID/IPsubnet_consolated.txt , VLAN_ID/IPsubnet_DNS.txt, VLAN_ID/IPsubnet_ICMP.txt # For debugging my $DEBUG =0; # Usage die "USAGE: $0 IP-dump-file ARP-dump-file ouiresolv-file DNS-dump-file\n" unless (@ARGV); # Input from user my $ipfile = $ARGV[0]; my $arpfile = $ARGV[1]; my $ouifile = $ARGV[2]; my $dnsfile = $ARGV[3]; print "\n You entered:$ipfile, $arpfile , $ouifile and $dnsfile \n" if $DEBUG; # Open the ip dump file for processing open(INPUT_FILE1,$ipfile) || die "Cannot open file $ipfile\n"; # Create a file handler. my @all_ip=; # Save the array input_file_contents . close(INPUT_FILE1); # Close the file handler open(INPUT_FILE2,$arpfile) || die "Cannot open file $arpfile\n"; # Create a file handler. my @arp_data=; # Save the array input_file_contents . close(INPUT_FILE2 ); # Close the file handler open(INPUT_FILE3,$ouifile) || die "Cannot open file $ouifile\n"; # Create a file handler. my @oui_data=; # Save the array input_file_contents . close(INPUT_FILE3); # Close the file handler open(INPUT_FILE4,$dnsfile) || die "Cannot open file $dnsfile\n"; # Create a file handler. my @dns_data=; # Save the array input_file_contents . close(INPUT_FILE4); # Close the file handler # Generate the names for the three output reports my @temp=split(/-/,$ipfile); my $name=$temp[0]; my $all_report=$name."_consolidated_report.txt"; my $icmp_report=$name."_icmp_err_report.txt"; my $dns_report=$name."_dns_err_report.txt"; open(OUT1,">$all_report") || die "Cannot open $all_report : $!"; # Create a file handler. print OUT1 "IP\tMAC\tOID\tDNS\n"; open(OUT2,">$icmp_report") || die "Cannot open $icmp_report : $!"; # Create a file handler. #print OUT2 "IP\n"; open(OUT3,">$dns_report") || die "Cannot open $dns_report : $!"; # Create a file handler. #print OUT3 "IP\n"; # Process all IP addresses my @interfaces = (); my $line = ""; my $intnum = 0; my $intinfo = {}; foreach $ip (@all_ip) { chomp($ip); #chop($ip); $intinfo = {}; $intinfo->{'ip'} = $ip; my $arp_flag=0; foreach $arp (@arp_data) { my @temp = split(/\s+/,$arp); my $arp_ip=$temp[0]; my $mac=$temp[1]; chomp($arp_ip); if ($ip eq $arp_ip) { print "Equal $ip:$arp_ip:$mac\n" if $DEBUG; $intinfo->{'mac'} = $mac; $arp_flag=1; } } if ($arp_flag == 0) { print "Cannot ping $ip - icmp error\n" if $DEBUG; print OUT2 "$ip\n"; } foreach $oui (@oui_data) { my @temp1 = split(/\s\-\>\s/,$oui); my $oui_ip=$temp1[0]; my $oui_value=$temp1[1]; chomp($oui_ip); chomp($oui_value); #chop($oui_value); if ($ip eq $oui_ip) { print "Equal $ip:$oui_ip:$oui_value\n" if $DEBUG; $intinfo->{'oui'} = $oui_value; } } my $dns_flag=0; foreach $dns (@dns_data) { my @temp2 = split(/\s/,$dns); my $dns_ip=$temp2[0]; my $dns_value=$temp2[1]; chomp($dns_ip); chomp($dns_value); if ($ip eq $dns_ip) { print "Equal $ip:$dns_ip:$dns_value\n" if $DEBUG; $intinfo->{'dns'} = $dns_value; $dns_flag=1; } } if ($dns_flag == 0) { print "Cannot resolve $ip - dns error\n" if $DEBUG; print OUT3 "$ip\n"; } push @interfaces,$intinfo; } foreach $int (@interfaces) { print "IP:$$int{ip} MAC:$$int{mac} OUI:$$int{oui} DNS:$$int{dns}\n" if $DEBUG ; my $ip=$$int{ip}; my $mac=$$int{mac}; my $oui=$$int{oui}; if (! $oui) { $oui= "Empty"; } my $dns=$$int{dns}; if (! $dns) { $dns = "Unresloved"; } print OUT1 "$ip\t$mac\t$oui\t$dns\n"; } close OUT1; close OUT2; close OUT3; close INPUT_FILE; print "Done\n";