如何使用Golang进行TCP SYN端口扫描?

3
我正在尝试使用golang编写tcp syn端口扫描器,我在这里找到了C语言版本的解决方案:http://www.binarytides.com/tcp-syn-portscan-in-c-with-linux-sockets/。我想在go中实现它,那么我该如何发送像这样的 tcp头呢?
//TCP Header
    tcph->source = htons ( source_port );
    tcph->dest = htons (80);
    tcph->seq = htonl(1105024978);
    tcph->ack_seq = 0;
    tcph->doff = sizeof(struct tcphdr) / 4;      //Size of tcp header
    tcph->fin=0;
    tcph->syn=1;
    tcph->rst=0;
    tcph->psh=0;
    tcph->ack=0;
    tcph->urg=0;
    tcph->window = htons ( 14600 );  // maximum allowed window size
    tcph->check = 0; //if you set a checksum to zero, your kernel's IP stack should fill in the correct checksum during transmission
    tcph->urg_ptr = 0;

我是否必须使用syscall或cgo?如果有人能帮助我解决这个问题,我会非常感激。

1个回答

0
你需要使用系统调用。然而,syscall包在不同的操作系统上可能不具备可移植性,所以如果这对你很重要,那么你就需要编写每个操作系统的版本,并使用file_os.go命名方案来保存特定于操作系统的代码。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接