linux arping命令學習

來源:互聯網
上載者:User

linux arping命令學習 arping命令用來向鄰近的主機發生ARP REQUEST資料包。 1. arping命令可以用來測試區域網路各個主機之間的連通性,不能用於測試其是否能與互連網連通,sh-# ping www.google.comPING www.google.com (74.125.239.147) 56(84) bytes of data.64 bytes from nuq05s02-in-f19.1e100.net (74.125.239.147): icmp_req=1 ttl=53 time=267 ms64 bytes from nuq05s02-in-f19.1e100.net (74.125.239.147): icmp_req=2 ttl=53 time=269 ms64 bytes from nuq05s02-in-f19.1e100.net (74.125.239.147): icmp_req=3 ttl=53 time=289 ms^C--- www.google.com ping statistics ---4 packets transmitted, 3 received, 25% packet loss, time 3011msrtt min/avg/max/mdev = 267.321/275.337/289.108/9.790 ms sh-# arping -I eth0 www.google.com -w 5ARPING 74.125.239.147 from 192.168.0.153 eth0Sent 6 probes (6 broadcast(s))Received 0 response(s)sh-# arping -I eth0 192.168.0.151 -w 5ARPING 192.168.0.151 from 192.168.0.153 eth0Unicast reply from 192.168.0.151 [78:52:1A:4D:D0:A5]  56.882msUnicast reply from 192.168.0.151 [78:52:1A:4D:D0:A5]  280.078msUnicast reply from 192.168.0.151 [78:52:1A:4D:D0:A5]  92.872msUnicast reply from 192.168.0.151 [78:52:1A:4D:D0:A5]  116.720msUnicast reply from 192.168.0.151 [78:52:1A:4D:D0:A5]  129.921msUnicast reply from 192.168.0.151 [78:52:1A:4D:D0:A5]  48.195msSent 6 probes (1 broadcast(s))Received 6 response(s) 2. arping命令可以用來測試區域網路中某個特定的IP地址是否已經被佔用。我們知道區域網路中如果IP地址有衝突可能會帶來各種奇怪的網路問題,所以arping命令在手動設定IP地址時會非常有用。可以在設定IP地址之前,使用arping命令進行測試。利用arping命令執行的返回碼來確認執行結果:如果返回結果為1,說明區域網路中已經存在該IP地址了;如果返回結果為0,說明區域網路中暫時無人使用該IP地址,那我們就可以使用了。sh-# arping -I eth0 -D 192.168.0.151 -w 5ARPING 192.168.0.151 from 0.0.0.0 eth0Unicast reply from 192.168.0.151 [78:52:1A:4D:D0:A5]  141.406msSent 1 probes (1 broadcast(s))Received 1 response(s)sh-# echo $?1sh-# arping -I eth0 -D 192.168.0.152 -w 5ARPING 192.168.0.152 from 0.0.0.0 eth0Sent 6 probes (6 broadcast(s))Received 0 response(s)sh-# echo $?0sh-# 問題:如果你的C應用程式需要通過檢查IP地址是否可用來決定使用者介面如何顯示,要怎麼做?這就要藉助於linux提供的庫函數system函數了。#include <stdlib.h>if (0 == system("arping -I eth0 -D 192.168.10.123 -w 5")){    printf("\nip not exist, can use this ip\n");}else{    printf("\nip exist, can not use this ip\n");}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.