VMware Cloud Community
TheVMinator
Expert
Expert

Discovering all Devices in a subnet using ESXCLI

I'd like to run a ping command using ESXCLI that does the following:

Utilizes a specific vmkernel port to run on so I can test the functionality using that vmkernel port.

Pings every host in a given subnet to determine what IPs are online in that subnet.

How can I do this with ESXCLI?

Thanks!

0 Kudos
4 Replies
jrmunday
Commander
Commander

It is possible to ping using a specific interface with ESXCLI, but not sure how you would loop this through every IP address.

~ # esxcli network diag ping --help

Usage: esxcli network diag ping [cmd options]

Description:

  ping                  Send ICMP echo requests to network hosts.

Cmd options:

  -c|--count=<long>     Specify the number of packets to send.

  -D|--debug            VMKPing debug mode.

  -d|--df               Set DF bit on IPv4 packets.

  -H|--host=<str>       Specify the host to send packets to. (required)

  -I|--interface=<str>  Specify the outgoing interface.

  -i|--interval=<str>   Set the interval for sending packets in seconds.

  -4|--ipv4             Ping with ICMPv4 echo requests.

  -6|--ipv6             Ping with ICMPv6 echo requests.

  --netstack=<str>      Specify the TCP/IP netstack which the interface resides on

  -N|--nexthop=<str>    Override the system's default route selection, in dotted quad notation. (IPv4 only. Requires interface option)

  -s|--size=<long>      Set the payload size of the packets to send.

  -t|--ttl=<long>       Set IPv4 Time To Live or IPv6 Hop Limit

  -W|--wait=<str>       Set the timeout to wait if no responses are received in seconds.

~ #

Why don't you write a PowerShell script to do this as you will have a lot more flexibility, and can still use ESXCLI with the Get-Exscli cmdlet.

Cheers,

Jon

vExpert 2014 - 2022 | VCP6-DCV | http://www.jonmunday.net | @JonMunday77
zXi_Gamer
Virtuoso
Virtuoso

Pings every host in a given subnet to determine what IPs are online in that subnet.

I would doubt that logic would work, since the ips which reply can also be a gateway, dns, or other workstations,  neways, you could come with a simple script like

for i in `seq 255`; do for j in `seq 255`; do echo 192.168.$i.$j; esxcli network diag ping -H 192.168.$i.$j -I vmk0 -c 1 | grep -i Recieved | awk '{if($2 == 1) {print "Alive"} else print "Dead"}'; done; done

TheVMinator
Expert
Expert

ok thanks.  PowerCLI won't work in this case as I need to use this on new hosts that haven't been joined to vcenter server yet and are in a new subnet.  Also, is there anyway to write that script to a file, and then download the file to my pc, given that I can't connect yet with putty but only through the esxi shell since the networking is still not configured yet when I'm doing this research?

0 Kudos
zXi_Gamer
Virtuoso
Virtuoso

If you mean you want the output to a file, then

for i in `seq 255`; do for j in `seq 255`; do echo 192.168.$i.$j; esxcli network diag ping -H 192.168.$i.$j -I vmk0 -c 1 | grep -i Recieved | awk '{if($2 == 1) {print "Alive"} else print "Dead"}' >> Discovery.txt; done; done

0 Kudos