Skip to content
Discussion options

You must be logged in to vote
import socket
import select
import time
import os

def send_and_rst(host, port, message=b"HELLO", wait_time=1):
    # 创建 TCP socket
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.setblocking(0)

    try:
        s.connect_ex((host, port))
        print(f"[+] Connecting to {host}:{port}")
        time.sleep(0.2)  # 等待连接建立

        # 发送数据
        s.sendall(message)
        print(f"[+] Sent data: {message}")

        # 等待一段时间
        time.sleep(wait_time)

        # 检查是否有数据可读
        rlist, _, _ = select.select([s], [], [], 0)
        if rlist:
            print("[!] Data available to read — closing fd to trigger RST")
            fd = s.fileno()
            os.close(fd)  # …

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by CottonTnT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant