chrisred / posh-scripts

11 stars 4 forks source link

ResolveAddress don't work? #1

Open mr-aleks opened 6 years ago

mr-aleks commented 6 years ago

Hi, I really like your script "Invoke-PingLog" But I can not understand the parameter "ResolveAdress" does not work or should it be? My command output:

PS C:\Users\mr_aleks> Invoke-PingLog 8.8.8.8 -Count 4 -ResolveAddres

Timestamp            ProtocolAddress                ReplySize  ResponseTime ResponseTTL  Status
---------            ---------------                ---------  ------------ -----------  ------
2018-04-23 16:55:53  8.8.8.8                        32         23           56           Success
2018-04-23 16:55:54  8.8.8.8                        32         23           56           Success
2018-04-23 16:55:55  8.8.8.8                        32         26           56           Success
2018-04-23 16:55:56  8.8.8.8                        32         23           56           Success

Ping statistics for 8.8.8.8 [8.8.8.8]:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss)
Approximate round trip time in milli-seconds:
    Minimum = 23ms, Maximum = 26ms, Average = 24ms

PS C:\Users\mr_aleks> Invoke-PingLog 8.8.8.8 -Count 4

Timestamp            ProtocolAddress                ReplySize  ResponseTime ResponseTTL  Status
---------            ---------------                ---------  ------------ -----------  ------
2018-04-23 16:56:01  8.8.8.8                        32         23           56           Success
2018-04-23 16:56:02  8.8.8.8                        32         23           56           Success
2018-04-23 16:56:03  8.8.8.8                        32         23           56           Success
2018-04-23 16:56:04  8.8.8.8                        32         23           56           Success

Ping statistics for 8.8.8.8:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss)
Approximate round trip time in milli-seconds:
    Minimum = 23ms, Maximum = 23ms, Average = 23ms
chrisred commented 6 years ago

Hey, glad it was helpful. -ResolveAddress should work, and does work for me at least. It will place the hostname it resolved into the summary after a session has stopped.

If your machine can resolve the address then Invoke-Pinglog should be able to resolve it too. Does the command nslookup 8.8.8.8 resolve correctly? Do you have more than one network adapter enabled on your machine?

PS C:\Users\Chris> .\Invoke-PingLog.ps1 8.8.8.8 -ResolveAddress

Timestamp            ProtocolAddress                ReplySize  ResponseTime ResponseTTL  Status
---------            ---------------                ---------  ------------ -----------  ------
2018-04-23 16:54:28  8.8.8.8                        32         16           55           Success
2018-04-23 16:54:29  8.8.8.8                        32         16           55           Success
2018-04-23 16:54:30  8.8.8.8                        32         15           55           Success

Ping statistics for 8.8.8.8 [google-public-dns-a.google.com]:
    Packets: Sent = 6, Received = 6, Lost = 0 (0% loss)
Approximate round trip time in milli-seconds:
    Minimum = 15ms, Maximum = 17ms, Average = 16ms
mr-aleks commented 6 years ago

Does the command nslookup 8.8.8.8 resolve correctly?

I understand that no?

PS C:\Users\mr_aleks> nslookup 8.8.8.8
╤хЁтхЁ:  csp3.zte.com.cn
Address:  fe80::1

╚ь :     8.8.8.8.in-addr.arpa
Address:  8.8.8.8

But I still see it like this: [8.8.8.8]

PS C:\Users\mr_aleks> Invoke-PingLog.ps1 8.8.8.8 -ResolveAddress -Count 4

Timestamp            ProtocolAddress                ReplySize  ResponseTime ResponseTTL  Status
---------            ---------------                ---------  ------------ -----------  ------
2018-04-23 23:27:17  8.8.8.8                        32         24           56           Success
2018-04-23 23:27:18  8.8.8.8                        32         23           56           Success
2018-04-23 23:27:19  8.8.8.8                        32         24           56           Success
2018-04-23 23:27:20  8.8.8.8                        32         23           56           Success

Ping statistics for 8.8.8.8 [8.8.8.8]:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss)
Approximate round trip time in milli-seconds:
    Minimum = 23ms, Maximum = 24ms, Average = 24ms

Do you have more than one network adapter enabled on your machine?

Yes, but the second one is off.

I checked it like this, and it output correctly.

PS C:\Users\mr_aleks> $IP = "8.8.8.8"
$ResolvingResults = ""
$ResolvingResults = @()
$IPList += @($IP)
foreach ($IP in $IPList) {
        try {$ResolvingResults += [System.Net.Dns]::GetHostEntry($IP)}
        catch{Write-Host $IP could not be Resolved -BackgroundColor Black -ForegroundColor Red}
        } 

$ResolvingResults | Select AddressList, HostName

AddressList HostName                      
----------- --------                      
{8.8.8.8}   google-public-dns-a.google.com
chrisred commented 6 years ago

If you open a PowerShell console run the lines below what do you get? Is it different from ([System.Net.Dns]::GetHostEntry('8.8.8.8')).HostName.

$Address = '8.8.8.8'
$PingStatus = Get-WmiObject -Query ("SELECT * FROM Win32_PingStatus WHERE Address='$Address' AND ResolveAddressNames='TRUE'")
$PingStatus.ProtocolAddressResolved

Looks like you have some traffic going over IPv6 from the nslookup output, that maybe effecting something.

mr-aleks commented 6 years ago

Print correctly:

PS C:\Users\mr_aleks> ([System.Net.Dns]::GetHostEntry('8.8.8.8')).HostName
google-public-dns-a.google.com

But

PS C:\Users\mr_aleks> $Address = '8.8.8.8'
$PingStatus = Get-WmiObject -Query ("SELECT * FROM Win32_PingStatus WHERE Address='$Address' AND ResolveAddressNames='TRUE'")
$PingStatus.ProtocolAddressResolved
8.8.8.8
chrisred commented 6 years ago

Sorry I got busy for a while. I suspect this is to do with IPv6 on your local network changing how WMI does name resolution. I'll put it down as something to test when i have a chance.

Thanks