感謝您花時間看看這個!Python:線程ARP ping的奇怪輸出
我遇到的問題是我的線程ARP腳本的輸出。我試圖實現的是將每個活動主機輸出的IP地址,MAC地址和NIC供應商都命令提示符。
我有一個老的ARP腳本沒有線程,這需要大約90秒,並打印我的理想輸出。
下面是我的新腳本,基於上述腳本,使用線程。不幸的是,我不知道爲什麼輸出中沒有顯示值。如果有人能幫助我,我將非常感激!
提前致謝!
def arp2(ip):
# An ARP scanner for the network.
ips = []
global ans, unans
ans, unans = srp(Ether(dst="ff:ff:ff:ff:ff:ff")/ARP(pdst=ip), timeout=2, verbose=0)
for snd, rcv in ans:
#Assign MAC address and IP address to variables mac and ipaddr
mac = rcv.sprintf(r"%Ether.src%")
ipaddr = rcv.sprintf(r"%ARP.psrc%")
#Get NIC vendor code from MAC address
niccode = mac[:8]
niccode = niccode.upper()
print ips
ips.append("end")
#ARPips file amendments
with open('C:\Python26\ARPips.prn', 'w+') as f:
f.write("\n".join(map(lambda x: str(x), ips)) + "\n")
#String lookup for NIC vendors. DO NOT CHANGE 'r' TO ANY OTHER VALUE.
with open('C:\Users\TomVB\Desktop\OID2.prn', 'r') as file:
for line in file:
if niccode in file:
return mac, ipaddr, line[8:]
def main():
print "Discovering..."
print ""
print "MAC Address \t \t IP Address \t NIC Vendor"
pool = Pool(processes=12)
Subnetlist = []
for i in range(255):
Subnetlist.append(str(IPInt+str(i)))
global ARPresults
ARPresults = pool.map(arp2, Subnetlist)
pool.close()
pool.join()
print "\n".join(ARPresults)
if __name__ == '__main__':
main()
這個劇本給了我下面的輸出:
Mac Address IP address NIC Vendor
[][]
[]
[]
[]
[]
[][]
[]
[]
等這樣的周邊的200線。
[重讀我的回答你剛纔的問題。這個問題是類似的](http://stackoverflow.com/q/22330003/4279) – jfs
嘿@ J.F.Sebastian,感謝您看到這個,我想這個時候我寫了這個腳本。你知道爲什麼它沒有打印,即使mac和ipaddr被返回,地圖選擇它們嗎?我覺得我錯過了一些非常明顯的東西): –
上一個問題中的第一個問題:'ping()'不會返回任何內容,但是您正嘗試打印其結果。 'arp2()'返回什麼? – jfs