RT, 我这有两个端口扫描器, 一个是才用connect, 一个是syn半开放. 我连接的是家庭路由器, 我用两个扫描器同时扫描192.168.1.1-192.168.1.254 connect的能扫描到192.168.1.1的80端口 但是syn方法的不能. 请问是我代码有问题 还是防火墙扫描的问题么?
我把SYN的扫描部分代码贴上来
DWORD WINAPI scan(LPVOID lp)
{
WSADATA WSAData;
WSAStartup(MAKEWORD(2,2) ,&WSAData);
int timeout;
SOCKET sock=NULL;
IPANDPORT* lpInfor=(IPANDPORT*)lp;
USHORT port=lpInfor->PORT;
SOCKADDR_IN addr_in={0};
addr_in.sin_family=AF_INET;
addr_in.sin_port=htons(port);
addr_in.sin_addr.S_un.S_addr=lpInfor->NETIP;
IPHEADER ipHeader;
TCPHEADER tcpHeader;
PSD_HEADER psdHeader;
char szSendBuf[60] = "";
ULONG ul=1;
if((sock = WSASocket(AF_INET, SOCK_RAW, IPPROTO_RAW, NULL, 0, WSA_FLAG_OVERLAPPED)) == INVALID_SOCKET)
{
AfxMessageBox("Socket Setup Errorl...");
return 0;
}
if(setsockopt(sock, IPPROTO_IP, IP_HDRINCL, (char *)&ul, sizeof(ul)) == SOCKET_ERROR)
{
AfxMessageBox("Setsockopt IP_HDRINCL Error...");
return 0;
}
timeout = 1000;
if(setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, (char *)&timeout, sizeof(timeout)) == SOCKET_ERROR)
{
AfxMessageBox("Setsockopt SO_SNDTIMEO Error...");
return 0;
}
ipHeader.h_verlen = (4<<4 | sizeof(ipHeader)/sizeof(unsigned long));
ipHeader.total_len = htons(sizeof(ipHeader)+sizeof(tcpHeader));
ipHeader.ident = 1;
ipHeader.frag_and_flags = 0x40;
ipHeader.ttl = 128;
ipHeader.proto = IPPROTO_TCP;
ipHeader.checksum = 0;
ipHeader.sourceIP = inet_addr(srcIP);
ipHeader.destIP = lpInfor->NETIP;
tcpHeader.th_sport = htons(srcPort);
tcpHeader.th_seq = 0x12345678;
tcpHeader.th_ack = 0;
tcpHeader.th_lenres = (sizeof(tcpHeader)/4<<4|0);
tcpHeader.th_flag = 2;//syn标志位
tcpHeader.th_win = htons(512);
tcpHeader.th_urp = 0;
tcpHeader.th_sum = 0;
psdHeader.saddr = ipHeader.sourceIP;
psdHeader.daddr = ipHeader.destIP;
psdHeader.mbz = 0;
psdHeader.ptcl = IPPROTO_TCP;
psdHeader.tcpl = htons(sizeof(tcpHeader));
ipHeader.checksum = 0;
tcpHeader.th_sum = 0;
tcpHeader.th_dport = htons(port);
addr_in.sin_family=AF_INET;
addr_in.sin_port=htons(port);
addr_in.sin_addr.S_un.S_addr=lpInfor->NETIP;
//sin.sin_family = AF_INET;
//sin.sin_port = htons(tmp);
//sin.sin_addr.S_un.S_addr = inet_addr((char *)targetIP);
memcpy(szSendBuf, &psdHeader, sizeof(psdHeader));
memcpy(szSendBuf + sizeof(psdHeader), &tcpHeader, sizeof(tcpHeader));
tcpHeader.th_sum = Checksum((USHORT *)szSendBuf, sizeof(psdHeader) + sizeof(tcpHeader));
memcpy(szSendBuf, &ipHeader, sizeof(ipHeader));
memcpy(szSendBuf + sizeof(ipHeader), &tcpHeader, sizeof(tcpHeader));
memset(szSendBuf + sizeof(ipHeader) + sizeof(tcpHeader), 0, 4);
ipHeader.checksum = Checksum((USHORT *)szSendBuf, sizeof(ipHeader) + sizeof(tcpHeader));
memcpy(szSendBuf, &ipHeader, sizeof(ipHeader));
memcpy(szSendBuf + sizeof(ipHeader), &tcpHeader, sizeof(tcpHeader));
int ret = sendto(sock, szSendBuf, sizeof(ipHeader) + sizeof(tcpHeader), 0, (struct sockaddr *)&addr_in, sizeof(addr_in));