udp端口掃描程序代碼.doc_第1頁
udp端口掃描程序代碼.doc_第2頁
udp端口掃描程序代碼.doc_第3頁
udp端口掃描程序代碼.doc_第4頁
全文預(yù)覽已結(jié)束

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

。/ udp.cpp : 定義控制臺應(yīng)用程序的入口點。/#include stdafx.h #include #include #pragma comment(lib, ws2_32.lib) #define MAXBUFF 8192 #define ICMP_UNREACH_PORT 3 #define ICMP_UNREACH 4 enum CMD_NAME, DST_IP, START_PORT, LAST_PORT; structip unsigned int ip_v:4; / 版本unsigned int ip_hl:4; / 頭部長unsigned char ip_tos; / 服務(wù)類型unsigned short ip_len; / 總長unsigned short ip_id; /鑒定域unsigned short ip_flags; /IP標志unsigned short ip_off; / 片偏移unsigned char ip_ttl; / TTL unsigned char ip_protocol; / 協(xié)議unsigned short ip_sum; / 頭部效驗和structin_addrip_src, ip_dest; /源ip和目的IP #define IP_RF 0x8000 / 標記收到數(shù)據(jù)#define IP_DF 0x4000 #define IP_MF 0x2000 #define IP_OFFMASK 0x1fff ; structicmp unsigned short inticmp_type; unsigned short inticmp_code; unsigned long inticmp_cksum; unsigned long inticmp_id; unsigned long inticmp_seq; unsigned short inticmp_data1; ; int main(intargc, char *argv) structtimevaltv; fd_setselect_fd; char buffMAXBUFF; intdstport, startport, endport; if (argc != 4) fprintf(stdout, usage: %s 目的ip起始端口目的端口n, argvCMD_NAME); exit(EXIT_FAILURE); WSADatawsaData; WSAStartup(MAKEWORD(2,2), &wsaData); structsockaddr_insend_sa; / 發(fā)送端地址信息memset(&send_sa, 0, sizeof(send_sa); send_sa.sin_family = AF_INET; send_sa.sin_addr.s_addr = inet_addr(argvDST_IP); startport = atoi(argvSTART_PORT); endport = atoi(argvLAST_PORT); SOCKET sock_send = socket(AF_INET, SOCK_DGRAM, 0); / 發(fā)送用的描述符if (sock_send 0) perror( sock(SOCK_DGRAM); closesocket(sock_send); exit(EXIT_FAILURE); SOCKET sock_recv = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP); / 接收用的描述符if (sock_recv 0) perror( socket(SOCK_RAW); closesocket(sock_recv); exit(EXIT_FAILURE); for (dstport = startport; dstport 0) structip *ip; structicmp *icmp; inthlen; int port; memset(&ip, 0, sizeof(ip); if (recvfrom(sock_recv, buff, MAXBUFF, 0, NULL, NULL) != 56) continue; ip = (structip *)buff; hlen = ip-ip_hlip_src.s_addr != send_sa.sin_addr.s_addr) | (icmp-icmp_type != ICMP_UNREACH) | (icmp-icmp_code != ICMP_UNREACH_PORT) | (port != dstport) continue; else structservent *se; se = getservbyport(htons(dstport), udp); if (se != NULL) printf(%5d %-20sn, dstport, (se = NULL) ? unknown: se-s_name); break; closesocket(sock_s

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論