Помогает ли это?
[mpenning@Bucksnort ~]$ arp -an
? (4.121.8.3) at 08:00:27:f5:5b:6b [ether] on eth0
? (4.121.8.4) at 08:00:27:f5:5b:6b [ether] on eth0
? (4.121.8.1) at 00:1b:53:6b:c9:c4 [ether] on eth0
[mpenning@Bucksnort ~]$
В питоне ...
#!/usr/bin/env python
import subprocess
import re
def parse_arpline(line, hosts):
match = re.search(r'\((\S+?)\)\s+at\s+(\S+)', line)
if match is not None:
ipaddr = match.group(1)
mac = match.group(2)
hosts.append((ipaddr, mac))
return hosts
SUBNET = '192.168.1.0/24' # Insert your subnet here
subprocess.Popen([r"nmap","-sP", SUBNET],stdout=subprocess.PIPE).communicate()
p = subprocess.Popen([r"arp","-an"],stdout=subprocess.PIPE).communicate()[0].split('\n')
hosts = []
ii = 0
for line in p:
hosts = parse_arpline(line, hosts)
ii +=1
# Iterate and do something with the hosts list
print hosts
в перл ...
my $SUBNET = '192.168.1.0/24'; # Insert your subnet here
`nmap -sP $SUBNET`;
my $p = `arp -an`;
for my $line (split('\n', $p)) {
$line=~/\((\S+?)\)\s+at\s+(\S+)/;
$ipaddr = $1;
$mac = $2;
# do something with with each mac and ip address
}