from scapy.all import *
import threading
import os
host_list = {}
num = 0
threadLock = threading.Lock()
threads = []
def printHosts(host_list):
print('-------------------------- HOST LIST --------------------------')
print('NUM IP MAC')
print('---------------------------------------------------------------')
for num in host_list:
ip, mac = host_list[num]
print("%d %s %s" % (num, ip, mac))
print('---------------------------------------------------------------')
def getHosts(ip):
global host_list, num
ans, unans = srp(Ether(dst='ff:ff:ff:ff:ff:ff') / ARP(pdst=ip), timeout=5, retry=1)
for s, r in ans:
threadLock.acquire()
num = num + 1
host_list.update()
threadLock.release()
def main():
for i in range(1, 256):
ip = "192.168.0.%d" % i
th = threading.Thread(target=getHosts, args=(ip, ))
th.start()
threads.append(th)
for t in threads:
t.join()
os.system('clear')
printHosts(host_list)
if __name__ == '__main__':
main()
왜 인지는 모르겠지만 가끔가다 여러 개의 호스트에서 응답이 안돌아오는 경우가 있다.ㅠ
(와이어 샤크로 잡아봐도 마찬가지 ㅠㅠ)
'Programming > Python' 카테고리의 다른 글
pip UnicodeDecodeError 해결법 (0) | 2020.10.22 |
---|---|
Dictionary Attack (0) | 2020.03.04 |
ARP를 이용한 host scan (0) | 2020.02.24 |
ARP Spoofing (0) | 2020.02.24 |
cookie를 이용한 로그인 (0) | 2018.07.18 |
살아있는 호스트 IP 스캔하기 (0) | 2018.02.13 |
댓글0