---
title: "VC++实现局域网嗅探QQ号"
author: "winzenghua"
date: "2009-04-09T16:08:00Z"
tags: []
slug: "vc-qq"
draft: false
lastmod: "2009-04-09T16:08:00Z"
id: 948136
url: "https://java4gis.iteye.com/blog/948136"
---

#include &lt;afxsock.h&gt;  
#include&lt;winsock2.h&gt;  
#pragma comment(lib,"ws2\_32.lib")

#include &lt;ras.h&gt;  
#include &lt;raserror.h&gt;  
#pragma comment(lib, "rasapi32.lib")  
#include &lt;WinInet.h&gt;  
#pragma comment(lib, "WinInet.LIB")

#include &lt;Dlgs.h&gt;

#pragma comment(lib,"vfw32.lib")  
#pragma comment(lib,"winmm.lib")  
#define MAX\_HOSTNAME\_LAN 255  
#define SIO\_RCVALL \_WSAIOW(IOC\_VENDOR,1)  
#define MAX\_ADDR\_LEN 16  
struct ipheader {  
unsigned char ip\_hl:4, ip\_v:4; /* this means that each member is 4 bits \*/  
unsigned char ip\_tos;  
unsigned short int ip\_len;  
unsigned short int ip\_id;  
unsigned short int ip\_off;  
unsigned char ip\_ttl;  
unsigned char ip\_p;  
unsigned short int ip\_sum;  
unsigned int ip\_src;  
unsigned int ip\_dst;  
}; /* total ip header length: 20 bytes (=160 bits) \*/  
typedef struct udphdr {  
unsigned short sport;  
unsigned short dport;  
unsigned short len;  
unsigned short cksum;  
}UDP\_HDR;  
void main()  
{  
SOCKET sock;  
WSADATA wsd;  
DWORD dwBytesRet;  
unsigned int optval = 1;  
unsigned char \*dataudp,\*pUdpData;  
int QQ,iUdpDataLen;  
SOCKADDR\_IN sa,saSource, saDest;  
struct hostent FAR * pHostent;  
char FAR name\[MAX\_HOSTNAME\_LAN];  
char szSourceIP\[MAX\_ADDR\_LEN],RecvBuf\[65535] = {0};  
struct udphdr \*pUdpheader;  
struct ipheader \*pIpheader;  
WSAStartup(MAKEWORD(2,1),&wsd);  
if ((sock = socket(AF\_INET, SOCK\_RAW, IPPROTO\_IP))==SOCKET\_ERROR)exit(1);  
gethostname(name, MAX\_HOSTNAME\_LAN);  
pHostent = gethostbyname(name);  
sa.sin\_family = AF\_INET;  
sa.sin\_port = htons(6000);  
memcpy(&sa.sin\_addr.S\_un.S\_addr, pHostent-&gt;h\_addr\_list\[0], pHostent-&gt;h\_length);  
bind(sock, (SOCKADDR \*)&sa, sizeof(sa));  
if ((WSAGetLastError())==10013)exit(1);  
WSAIoctl(sock, SIO\_RCVALL, &optval, sizeof(optval), NULL, 0, &dwBytesRet, NULL, NULL);  
pIpheader = (struct ipheader \*)RecvBuf;  
pUdpheader = (struct udphdr \*) (RecvBuf+ sizeof(struct ipheader ));  
printf("QQ sniffer V1.1 code powerd by cooldiyer\\r\\n");  
while (1)  
{  
memset(RecvBuf, 0, sizeof(RecvBuf));  
recv(sock, RecvBuf, sizeof(RecvBuf), 0);  
saSource.sin\_addr.s\_addr = pIpheader-&gt;ip\_src;  
strncpy(szSourceIP, inet\_ntoa(saSource.sin\_addr), MAX\_ADDR\_LEN);  
iUdpDataLen =(ntohs(pIpheader-&gt;ip\_len)-(sizeof(struct ipheader)+sizeof(struct udphdr)));  
if((pIpheader-&gt;ip\_p)==IPPROTO\_UDP&&iUdpDataLen!=0)  
{  
pUdpData=(unsigned char \*) RecvBuf+sizeof(struct ipheader)+sizeof(struct udphdr);  
iUdpDataLen=ntohs(pIpheader-&gt;ip\_len)-(sizeof(struct ipheader)+sizeof(struct udphdr));  
if(ntohs(pUdpheader-&gt;dport)==8000)  
if(iUdpDataLen%4==0 && iUdpDataLen&gt;0)  
if(pUdpData\[0]==0x02 && pUdpData\[3]==0x00 && pUdpData\[iUdpDataLen-1]==0x03)  
{  
QQ = (pUdpData\[7]&0xff);  
QQ = (QQ&lt;&lt;8) + (pUdpData\[8]&0xff);  
QQ = (QQ&lt;&lt;8) + (pUdpData\[9]&0xff);  
QQ = (QQ&lt;&lt;8) + (pUdpData\[10]&0xff);  
printf("IP:%s QQ:%d\\r",szSourceIP,QQ);  
}  
}  
}  
}

需要源码的请留下E-mail,我给你们发