标签:python except import target 数据包y
import threading import time from netaddr import IPNetwork,IPAddress --snip-- #监听的主机 host = "192.168.0.187" #扫描的目标子网 subnet = "192.168.0.0/24" #自定义的字符串,我们将在ICMP相应中进行核对。 magic_message = "PYTHONRULE!" #批量发送UDP数据包 def udp_sender(subnet,magic_message): time.sleep(5) sender = socket.socket(socket.AF_INET,socket.SOCK_DGRAM) for ip in IPNetwork(subnet): try: sender.sendto(magic_message,("%s") % ip,65212) except: pass t = threading.Thread(target=udp_sender,args=(subnet,magic_message)) t.start() --snip-- try: while True: --snip-- #print "ICMP --> TYPE: %d Code: %d (icmp_header.type,icmp_header.code) #检查类型和代码值是否为3 if icmp_header.code == 3 and icmp_header.type==3: #确认相应的主机在我们目标子网之内 if IPAddress(ip_header.src_address) in IPNetwork(subnet): if raw_buffer[len(raw_buffer)-len(magic_message):]==magic_message print "Host up:%s" % ip_header.src_address.
本文出自 “专注php” 博客,请务必保留此出处http://jingshanls.blog.51cto.com/3357095/1833725
标签:python except import target 数据包y
原文地址:http://jingshanls.blog.51cto.com/3357095/1833725