Du bist hier: Snippet-Verzeichnis » Perl (198)
Sprache:

arpGet

Sprache: English
Programmiersprache: Perl
Veröffentlicht von: jauderho [nicht registriert]
Letzte Änderung: 15.05.2006
Aufrufe: 1057


Beschreibung

another way to get arp entries under solaristhis one is way faster than the arp command

Code

1 #!/usr/local/bin/perl 2 # 3 # arpGet 4 # 5 # Use ndd to get at the arp cache to find IP addresses in their address. This 6 # is for Solaris only. Don't look at the code too closely or you might go 7 # blind. 8 # 9 # 031097 jauderho [created] 10 # 11 12 use Socket; 13 14 open(ARPDATA,"ndd -get /dev/arp arp_cache_report |") or die "Can't use ndd\n"; 15 16 print "Hostname\t\tIP Address\t\tMAC Address\n"; 17 18 while (<ARPDATA>) { 19 if (/ifname/) { 20 next; # Ignore the first line. 21 } 22 23 ($interface,$ip,$broadcast,$mac,$flags) = /(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(.*)/; 24 25 $newip = nibbleIP($ip); # Get rid of unwanted zeros. 26 ($hostname) = gethostbyaddr(inet_aton($newip),AF_INET); 27 $hostname =~ s/\.transmeta\.com//; 28 29 printf("%-24s%-24s%-24s\n",$hostname,$newip,$mac); 30 } 31 32 sub nibbleIP { 33 my ($nibble) = @_; 34 35 # Nibble. Nibble. 36 $nibble =~ s/00(\d+)/$1/g; 37 $nibble =~ s/0(\d+)/$1/g; 38 39 return $nibble; 40 } 41

Noch kein Kommentar vorhanden

Dieses Snippet kommentieren

Name *  

E-Mail (wird nicht angezeigt) *    

Website  

Kommentar *  

Sicherheitscode Sicherheitscode *    

RSS