Difference between revisions of "Scan-subnet.pl"

From Organic Design wiki
m
(Change source-code blocks to standard format)
 
(4 intermediate revisions by one other user not shown)
Line 1: Line 1:
 
This little script uses [[w:nmap|nmap]] to give you a list of all the IP addresses in use on all the subnets on all active network interfaces on the host it is run on. It also gives the MAC address and a basic description for each.
 
This little script uses [[w:nmap|nmap]] to give you a list of all the IP addresses in use on all the subnets on all active network interfaces on the host it is run on. It also gives the MAC address and a basic description for each.
  
{{lowercase}}{{code|<perl>
+
{{lowercase}}<source lang="perl">
 
#!/usr/bin/perl
 
#!/usr/bin/perl
 
for ( qx( ifconfig ) =~ /inet addr:([0-9.]+)\.[0-9]+\s+Bcast:/g ) {
 
for ( qx( ifconfig ) =~ /inet addr:([0-9.]+)\.[0-9]+\s+Bcast:/g ) {
@_ = qx( nmap -nsL -O $_.0/24 ) =~ /^Host ([0-9.]+) not scanned.MAC Address: (.{17}).+?\((.+?).$/sgm;
+
@i = qx( nmap -nsL -O $_.0/24 ) =~ /^Host ([0-9.]+) not scanned.MAC Address: (.{17}).+?\((.+?).$/sgm;
while ( $#_ >= 0 ) {
+
print "".(shift @i)."\t[".(shift @i)."] ".(shift @i)."\n" while $#i >= 0;
( $ip, $mac, $os ) = ( shift @_, shift @_, shift @_ );
 
print "$ip\t [$mac] $os\n"
 
}
 
 
}
 
}
</perl>}}
+
</source>
 
+
*{{svn|tools|scan-subnet|This script is in the [[svn]] repository at}}
  
  
  
 
'''Example output:'''
 
'''Example output:'''
{{code|<pre>
+
<source>
 
192.168.1.1 [00:21:29:08:91:44] Cisco-Linksys
 
192.168.1.1 [00:21:29:08:91:44] Cisco-Linksys
 
192.168.1.2 [00:13:C0:03:12:A4] CompuLab
 
192.168.1.2 [00:13:C0:03:12:A4] CompuLab
Line 23: Line 20:
 
192.168.1.102 [00:08:6F:58:FF:0C] Senao International Co.
 
192.168.1.102 [00:08:6F:58:FF:0C] Senao International Co.
 
192.168.1.151 [00:1E:09:48:AA:34] Dell
 
192.168.1.151 [00:1E:09:48:AA:34] Dell
</pre>}}
+
</source>
  
  
 
[[Category:PERL]]
 
[[Category:PERL]]

Latest revision as of 18:11, 22 May 2015

This little script uses nmap to give you a list of all the IP addresses in use on all the subnets on all active network interfaces on the host it is run on. It also gives the MAC address and a basic description for each.

#!/usr/bin/perl
for ( qx( ifconfig ) =~ /inet addr:([0-9.]+)\.[0-9]+\s+Bcast:/g ) {
	@i = qx( nmap -nsL -O $_.0/24 ) =~ /^Host ([0-9.]+) not scanned.MAC Address: (.{17}).+?\((.+?).$/sgm;
	print "".(shift @i)."\t[".(shift @i)."] ".(shift @i)."\n" while $#i >= 0;
}
Info.svg This code is in our Git repository here.

Note: If there is no information in this page about this code and it's a MediaWiki extension, there may be something at mediawiki.org.


Example output:

192.168.1.1	 [00:21:29:08:91:44] Cisco-Linksys
192.168.1.2	 [00:13:C0:03:12:A4] CompuLab
192.168.1.100	 [00:02:D2:02:2E:D1] MacPower Peripherals
192.168.1.101	 [00:07:6F:58:FF:29] Senao International Co.
192.168.1.102	 [00:08:6F:58:FF:0C] Senao International Co.
192.168.1.151	 [00:1E:09:48:AA:34] Dell