시간을내어 주셔서 감사합니다!파이썬 : 스레드 ARP 핑을위한 이상한 결과
내가 겪고있는 문제는 내 스레드 ARP 스크립트의 출력과 관련이 있습니다. 내가 뭘 하려는지 명령 프롬프트에 각 살아있는 호스트 출력의 IP 주소, MAC 주소 및 NIC 공급 업체를 가지고있다.
스레딩이없는 오래된 ARP 스크립트가 있습니다.이 스크립트는 약 90 초가 걸리고 이상적인 출력을 인쇄합니다.
위의 스크립트를 기반으로하는 최신 스크립트 인 스레딩이 있습니다. 불행히도 출력에 값이 표시되지 않는 이유는 알 수 없습니다. 아무도 도와 줄 수 없다면 나는 매우 감사 할 것입니다!
미리 감사드립니다.
Mac Address IP address NIC Vendor
[][]
[]
[]
[]
[]
[][]
[]
[]
등이 같은 약 200 라인 :
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()
이 스크립트는 나에게 다음과 같은 출력을 제공합니다.
[이전 질문에 대한 내 대답을 다시 읽어 같다. 문제는 비슷합니다] (http://stackoverflow.com/q/22330003/4279) – jfs
헤이 @ J.F.Sebastian, 이걸 보아 주셔서 감사합니다.이 스크립트를 작성할 때 이것을 생각했습니다. Mac 및 ipaddr가 반환되고지도에서 가져온 경우에도 인쇄되지 않는 이유를 알고 있습니까? 나는 정말 명백한 것을 놓치고있는 것처럼 느낍니다.) : –
이전 질문의 첫 번째 문제 :'ping()'은 아무 것도 반환하지 않지만 결과를 출력하려고합니다. 'arp2()'는 아무것도 반환합니까? – jfs