建设银行江门市新会网站,专业微信网站,创业中文网站模板,网站运营核心地址信息在IP层, 可以利用 ICMP 或 ARP 协议数据包探测IP信息. ICMP协议可以利用ping工具发送数据包, 但是防火墙有可能禁止ICMP, 无法有效探测, 可以考虑使用ARP探测.
利用ICMP协议探测内网IP
def ping_ip(ip_fex):# 扫描范围: 128~254for i in range(128, 255):ip f{ip_fe…地址信息在IP层, 可以利用 ICMP 或 ARP 协议数据包探测IP信息. ICMP协议可以利用ping工具发送数据包, 但是防火墙有可能禁止ICMP, 无法有效探测, 可以考虑使用ARP探测.
利用ICMP协议探测内网IP
def ping_ip(ip_fex):# 扫描范围: 128~254for i in range(128, 255):ip f{ip_fex}.{i}print(f\r{ip}, end)output os.popen(fping -n 1 -w 100 {ip} | findstr TTL).read()if len(output) 0:print(f\n{ip} online)if __name__ __main__:ping_ip(192.168.110)
利用ARP协议探测内网IP
def ip_thread(start, ip_fex):for i in range(start, start 20):ip f{ip_fex}.{i} # 目标iptry:pkg ARP(psrcf{ip_fex}.1, pdstip) # 伪造ARP广播reply sr1(pkg, timeout1, verboseFalse) # 发送ARP并获取响应包if reply:print(f\n{ip}-{reply[ARP].hwsrc}) # 显示MAC地址else:print(f\r{ip} ..., end)except Exception as e:print(e)def ip_scan(ip_fex):# 关闭警告import logginglogging.getLogger(scapy.runtime).setLevel(logging.ERROR)# 端口范围 1~254for i in range(1, 255, 20): threading.Thread(targetip_thread, args(i, ip_fex)).start()
利用TCP协议探测端口
端口信息在TCP层, 可以使用TCP协议数据包探测端口是否开放 伪造 SYN 数据包, 根据响应数据中的标志位 flags 来判断端口是否正常响应. SYN: 0x002 ACK: 0x010 SYN-ACK: 0x012
def scan_port(ip):for port in range(22, 100):try:pkg IP(src192.168.112.123, dstip) / TCP(dportport, flagsS)reply sr1(pkg, timeout1, verboseFalse)if reply:if reply[TCP].flags 0x12: # SYN-ACKprint(fport-[{port}])except Exception as e:print(e)