#!/usr/bin/perl -w use strict; my $ip=''; my %hash=(); while(<>) { chomp; if (/\+/) { #we have an ip address...so parse it. my $temp=$_; $temp=~s/^\+\s//g; $ip=(split (/\s/,$temp))[0]; $ip=~s/\s//g; } if ($ip !~ /\d{3}\.\d{3}\.\d{1,3}\.\d{1,3}/) { #this should never happen print STDERR "Don't have an IP address...something is not right here...\n"; exit (-1); } push(@{$hash{$ip}},$_); } ###########################################3 #this will print a table like #IPADDRESS= # SERVER= # PORTNUMBER= # SERVICE= # DESCRIPTION= ####################################################### foreach my $ip_address (keys %hash) { print "IPADDRESS=$ip_address\n"; my $loop_num=0; foreach my $information (@{$hash{$ip_address}}) { #here is where you parse the information... #to get the servername, etc. #print "$information\n"; if ($loop_num == 0) { #you know this is the first entry, so this will have the server name my $server=(split(/\s/,$information))[-1]; print "\t\tSERVER=$server\n"; } elsif ($loop_num == 1) { #this will have the port number if ($information =~ /(\d+)/) { my $port_number=$1; print "\t\tPORTNUMBER=$port_number\n"; } my $service=(split(/\|\_\_\_/,$information))[1]; $service=join(" ",split(" ",$service)); #need to get the port number off the front... $service=~ s/^\d+//g; $service=join(" ",split(" ",$service)); print "\t\tSERVICE=$service\n"; } elsif ($loop_num == 2) { #here is your description my $description=(split(/\|\_\_\_/,$information))[1]; $description=join(" ",split(" ",$description)); print "\t\tDESCRIPTION=$description\n"; } $loop_num++; } }