Networking
cancel
Showing results for 
Search instead for 
Did you mean: 

how to write a ping program to ping arp table ip

eric wang_2
Frequent Advisor

how to write a ping program to ping arp table ip

I would like to ping ip in arp table cache,
but i don't know how to write a ping program to detect arp table ip host is alive, does any one know how to scan ip from(arp table cache) via ping program ,could any one give me an example ,thanks
3 REPLIES
Duncan Edmonstone
Honored Contributor

Re: how to write a ping program to ping arp table ip

eric,

how about something like this (tested on 11.31 - pings each address in the arp cache 3 times)

arp -an | cut -d'(' -f 2 | cut -d')' -f 1 | while read ip
do
ping ${ip} -n 3 >/dev/null 2>&1
[ $? -ne 0 ] && echo "Couldn't reach ${ip}"
done


HTH

Duncan

HTH

Duncan
eric wang_2
Frequent Advisor

Re: how to write a ping program to ping arp table ip

thanks for your reply, i would like to know if ping successful or not ,and when i run that program which shows nothing,
my HP-UX is B.11.31, and i am sure it has two arp record in arp table,and ping those ip which will response.


I would like to know if I need to write a c++ program to sure which ping status.

because i need to use program to check if host is live by that ip.

could any one tell me how to solve this IP Scan question.
Because i found i could use ECHO_REPLAY message to chech if ping is successful

thanks
Laurent Menase
Honored Contributor

Re: how to write a ping program to ping arp table ip

Hi Eric,

indeed, if you want to write a ping program by hand, you need to open a AF_INET,SOCK_RAW socket, then pseudo- connect() to the target address,
send a ICMP_ECHO, and wait for ICMP_ECHO_REPLY.

or timeout with select()