基于Windows下的udp扫描开端口

  • j4_458934
    了解作者
  • 1.1MB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-05-19 02:50
    上传日期
在Windows 下的udp 开放端口扫描 以及提供的服务
udpscan.rar
  • udpscan
  • Debug
  • vc60.pdb
    84KB
  • vc60.idb
    145KB
  • udpscan.pch
    3.5MB
  • udpscan.pdb
    441KB
  • udpscan.exe
    168.1KB
  • finger.obj
    15.9KB
  • udpscan.obj
    15.6KB
  • udpscan.ilk
    179.2KB
  • udpscan.ncb
    41KB
  • udpscan.dsp
    3.3KB
  • udpscan.cpp
    2.8KB
  • udpscan.plg
    751B
  • udpscan.opt
    47.5KB
  • udpscan.dsw
    537B
内容介绍
#include <stdio.h> #include <winsock2.h> #pragma comment(lib, "ws2_32.lib") typedef struct icmp_hdr { unsigned char type; //消息类型 unsigned char code; //代码 unsigned short checksum; //校验和 unsigned short id; //标识此请求的id unsigned short seq; //序列号 unsigned long timestamp; //时间戳 }ICMPHeader; typedef struct _iphdr { unsigned int h_len:4; // Length of the header unsigned int version:4; // Version of IP unsigned char tos; // Type of service unsigned short total_len; // Total length of the packet unsigned short ident; // Unique identifier unsigned short frag_and_flags; // Flags unsigned char ttl; // Time to live unsigned char proto; // Protocol (TCP, UDP etc) unsigned short checksum; // IP checksum unsigned int sourceIP; unsigned int destIP; } IPHeader; int UDPScanPort(int sport, int eport, char*strip ) { WSADATA wsaData; if( WSAStartup(MAKEWORD(2,2),&wsaData) != 0) return -1; char *szDestIp = strip;//"127.0.0.1"; char recvBuf[1024] = {0}; SOCKET sRaw = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP); sockaddr_in in; in.sin_family = AF_INET; in.sin_port = 0; in.sin_addr.S_un.S_addr = INADDR_ANY; if(bind(sRaw,(sockaddr*)&in, sizeof(in)) == SOCKET_ERROR) //绑定原始套接口 { printf("bind() failed\n"); return 0; } int port = sport;//1; SOCKET sSend = socket(AF_INET, SOCK_DGRAM, 0); //创建数据据报套件口 SOCKADDR_IN destAddr; destAddr.sin_family = AF_INET; destAddr.sin_addr.S_un.S_addr = inet_addr(szDestIp); int nRet; ICMPHeader *pICMPHdr; SOCKADDR_IN recvAddr; do { destAddr.sin_port = htons(port); printf("scan%d\n", port); nRet = ::sendto(sSend,"hello",5,0,(sockaddr*)&destAddr, sizeof(destAddr)); if(nRet == SOCKET_ERROR) { printf("sendto failed\n"); break; } int nLen = sizeof(recvAddr); int nRet = recvfrom(sRaw, recvBuf, 1024,0,(sockaddr*)&recvAddr, &nLen); if(nRet == SOCKET_ERROR) { if(::WSAGetLastError() == WSAETIMEDOUT) { printf("time out\n"); break; } else { printf("recvfrom() failed\n"); break; } } if(recvAddr.sin_addr.S_un.S_addr == destAddr.sin_addr.S_un.S_addr) { IPHeader *iphdr = (IPHeader *)recvBuf; int iplen = iphdr->h_len>>2; pICMPHdr = (ICMPHeader *)(recvBuf+iplen ); if(pICMPHdr->type == 3 && pICMPHdr->code ==3) ; else { struct servent *service; if((service = getservbyport(htons(port),"udp")) != NULL) { fprintf(stdout,"Unknown port %u, open.\tUDP service %s open.\n", port, service->s_name); } } } //Sleep(10); port++; }while(port <=eport); return 0; } int main() { UDPScanPort(0, 135, "127.0.0.1"); return 0; }
评论
    相关推荐