## tcptraceroute
body+="\r\n"
print("追踪到NLS服务器端口")
body+="追踪到NLS服务器端口"
body+="\r\n"
from scapy.all import sr1,IP,TCP
import sys

def tcp_traceroute(host, port, max_hops=30, timeout=1):
    info=""
    for ttl in range(1, max_hops + 1):
        pkt = IP(dst=host, ttl=ttl) / TCP(dport=port, flags="S")
        reply = sr1(pkt, verbose=0, timeout=timeout)
        try:
            if reply is None:
                print(f"{ttl} hops away: Request timed out")
                info+=f"{ttl} hops away: Request timed out"
                info+="\r\n"
            elif reply.type == 3:
                print(f"{ttl} hops away: {reply.src}")
                info+=f"{ttl} hops away: {reply.src}"
                info+="\r\n"
                break
            else:
                print(f"{ttl} hops away: {reply.src}")
                info+=f"{ttl} hops away: {reply.src}"
                info+="\r\n"
        except:
            continue
    return info
# 使用函数
host = "www.baidu.com"
port = 80
try:
    body+=tcp_traceroute(host, port)
    body+="\r\n"
except:
    print("进行此项测试,需要操作系统管理员权限。可能当前并没有权限。")
    body+="进行此项测试,需要操作系统管理员权限。可能当前并没有权限。"
    body+="\r\n"
最后修改:2024 年 05 月 11 日
如果觉得我的文章对你有用,请随意赞赏