File tree Expand file tree Collapse file tree 2 files changed +14
-8
lines changed Expand file tree Collapse file tree 2 files changed +14
-8
lines changed Original file line number Diff line number Diff line change @@ -71,7 +71,7 @@ def getmacbyip(ip, chainCC=0):
71
71
"""Return MAC address corresponding to a given IP address"""
72
72
if isinstance (ip , Net ):
73
73
ip = next (iter (ip ))
74
- ip = inet_ntoa (inet_aton (ip ))
74
+ ip = inet_ntoa (inet_aton (ip or "0.0.0.0" ))
75
75
tmp = [orb (e ) for e in inet_aton (ip )]
76
76
if (tmp [0 ] & 0xf0 ) == 0xe0 : # mcast @
77
77
return "01:00:5e:%.2x:%.2x:%.2x" % (tmp [1 ] & 0x7f , tmp [2 ], tmp [3 ])
@@ -85,13 +85,16 @@ def getmacbyip(ip, chainCC=0):
85
85
if mac :
86
86
return mac
87
87
88
- res = srp1 (Ether (dst = ETHER_BROADCAST ) / ARP (op = "who-has" , pdst = ip ),
89
- type = ETH_P_ARP ,
90
- iface = iff ,
91
- timeout = 2 ,
92
- verbose = 0 ,
93
- chainCC = chainCC ,
94
- nofilter = 1 )
88
+ try :
89
+ res = srp1 (Ether (dst = ETHER_BROADCAST ) / ARP (op = "who-has" , pdst = ip ),
90
+ type = ETH_P_ARP ,
91
+ iface = iff ,
92
+ timeout = 2 ,
93
+ verbose = 0 ,
94
+ chainCC = chainCC ,
95
+ nofilter = 1 )
96
+ except Exception :
97
+ return None
95
98
if res is not None :
96
99
mac = res .payload .hwsrc
97
100
conf .netcache .arp_cache [ip ] = mac
Original file line number Diff line number Diff line change @@ -10697,6 +10697,9 @@ test_IPID_count()
10697
10697
############
10698
10698
+ ARP
10699
10699
10700
+ = Simple Ether() / ARP() show
10701
+ (Ether() / ARP()).show()
10702
+
10700
10703
= ARP for IPv4
10701
10704
10702
10705
p = raw(ARP())
You can’t perform that action at this time.
0 commit comments