问题
Due to firewall constraints, the servers I deal with do not reply to a ping, but do give their IP address
for eg, if I do :
ping myhost.com
I get
Pinging myhost.com [192.1.1.1] with 32 bytes of data:
Request Timed Out.
How can I just get the IP of the server from powershell? I know it can be done various ways if a server responds to a ping (Test-Connection or Ping-Host) , but I cant figure it when it ignores ping requests
回答1:
You can use the System.Net.Dns.GetHostAddresses method. This method will return an array of System.Net.IPAddress objects.
Examples of usage:
$ipAddresses = [System.Net.Dns]::GetHostAddresses('google.com')
List all addresses:
$ipAddresses | %{$_.IPAddressToString}
Grab the first address in the array:
$ipAddresses[0].IPAddressToString
回答2:
You can try and resolve it by DNS:
[System.Net.Dns]::GetHostByName('google.com').AddressList
来源:https://stackoverflow.com/questions/12808161/get-the-ip-of-a-server-through-powershell-when-it-doesnt-respond-to-a-ping