david-c
9/15/2017 - 9:38 PM

Ping All ESXi Host IP Addresses

Validate ESXi host networking.

# Get a list of IP addresses with PowerCLI
$Vmhosts = 'ndesx*'
$Vmks = 'vmk1', 'vmk7'
Get-VMHostNetworkAdapter -VMHost $Vmhosts -Name $Vmks | sort VMHost, Name | ft -auto VMHost, Name, IP

# ESXi host Bash function to ping all vMotion addresses
ping_vmotion () {
    mtu=1472
    failures=0
    vmks="vmk0"
    addrs="10.1.15.130
    10.1.15.120
    10.1.15.40
    10.1.15.20
    10.1.15.30"
    
    for addr in $addrs
    do
        for vmk in $vmks
        do
            count=$(ping -c 1 -W .1 -I $vmk -d -s $mtu $addr | grep 'received' | awk -F',' '{ print $2 }' | awk '{ print $1 }')
            if [ $count -eq 0 ]; then
                echo "Ping failed: $addr ($vmk)"
                let failures=failures+1
            fi
        done
    done
    echo
    if [ $failures -eq 0 ]; then
        echo "Ping sweep complete. No failures detected."
    else
        echo "Ping sweep complete. Failures detected: $failures."
    fi
}
# Get a list of IP addresses with PowerCLI
$Vmhosts = 'sac0*'
$Vmks = 'vmk0'
Get-VMHostNetworkAdapter -VMHost $Vmhosts -Name $Vmks | sort VMHost, Name | ft -auto VMHost, Name, IP

# ESXi host Bash function to ping all management addresses
ping_mgmt () {
    mtu=1472
    failures=0
    vmks="vmk0"
    addrs="10.1.15.130
    10.1.15.120
    10.1.15.40
    10.1.15.20
    10.1.15.30"
    
    for addr in $addrs
    do
        for vmk in $vmks
        do
            count=$(ping -c 1 -W .1 -I $vmk -d -s $mtu $addr | grep 'received' | awk -F',' '{ print $2 }' | awk '{ print $1 }')
            if [ $count -eq 0 ]; then
                echo "Ping failed: $addr ($vmk)"
                let failures=failures+1
            fi
        done
    done
    echo
    if [ $failures -eq 0 ]; then
        echo "Ping sweep complete. No failures detected."
    else
        echo "Ping sweep complete. Failures detected: $failures."
    fi
}
# Get a list of IP addresses with PowerCLI
$Vmhosts = 'sac0esxi*'
$Vmks = 'vmk2', 'vmk3', 'vmk5', 'vmk6'
Get-VMHostNetworkAdapter -VMHost $Vmhosts -Name $Vmks | sort VMHost, Name | ft -auto VMHost, Name, IP

# ESXi host Bash function to ping all iSCSI addresses
ping_iscsi () {
    mtu=8972
    failures=0
    vmks="vmk2
    vmk3
    vmk5
    vmk6"
    addrs="10.10.100.3
    10.10.100.6
    10.10.100.7
    10.10.100.11
    10.10.100.12
    10.10.100.13"
    
    for addr in $addrs
    do
        for vmk in $vmks
        do
            count=$(ping -c 1 -W .1 -I $vmk -d -s $mtu $addr | grep 'received' | awk -F',' '{ print $2 }' | awk '{ print $1 }')
            if [ $count -eq 0 ]; then
                echo "Ping failed: $addr ($vmk)"
                let failures=failures+1
            fi
        done
    done
    echo
    if [ $failures -eq 0 ]; then
        echo "Ping sweep complete. No failures detected."
    else
        echo "Ping sweep complete. Failures detected: $failures."
    fi
}