.NET Framework - Win32_PingStatus (problem resolving hostname / ip adress)

Asked By Thorsten A. Oeltjen
18-Mar-10 11:20 AM
Hi
within a script i'm trying to ping a host. if it is reachable, the script
can go on.
'magic cap'
for this posting *g*
the script gave me back errors - i tried within the console and found
that there was an error in
the dns server. Okay - we fixed that and before we made an ipconfig
/flushdns i tried a little bit.

I expect, that if i use the IP-Adress of the host, a ping should always
work (if the host is up).
I thought so. Its different ... see below ...

My Question - how is ist possible that if i ping an ip-adress -
powershell resolves the name bound to
it an then back to the wrong ip-adress???

The statuscode was sometimes 11003 (host not reachable) or 0.

My problem - i have trust my programm if it says : sry - host ist not
reachable ...
because its intended to work as an automated script, deleting unised
files ...

........................................................................................................................................................................
Skriptsniplet
........................................................................................................................................................................
clear
function FunTest($TargetHost)
{
$return = Get-WmiObject Win32_PingStatus -filter
return ($return.statuscode)
}
$TargetHost = "10.40.61.10"
if (FunTest($TargetHost) -eq 0)
{
Write-Host "Target ist da"
}
else
{
Write-Host "Target ist nicht da"
}
........................................................................................................................................................................
/Skriptsniplet
........................................................................................................................................................................
Windows PowerShell
Copyright (C) 2009 Microsoft Corporation. Alle Rechte vorbehalten.
PS C:\Users\> $Targethost = "10.40.61.10"
PS C:\Users\> Get-WmiObject Win32_PingStatus -filter
protocoladdress
statuscode                            responsetime
---------------
----------                            ------------
10.40.61.10
0                                      13

PS C:\Users\thorsten.oeltjen> $Targethost = "deingfle01"
PS C:\Users\thorsten.oeltjen> Get-WmiObject Win32_PingStatus -filter
protocoladdress
statuscode responsetime
---------------
---------- ------------

11010
........................................................................................................................................................................
........................................................................................................................................................................
PS C:\Users\> ping-host 10.40.61.10
Pinging <name>.<fqn> [192.168.61.1] with 32 bytes of data:
DestinationHostUnreachable
TimedOut
DestinationHostUnreachable
TimedOut
Ping statistics for <name>.<fqn>:
Packets: Sent = 4 Received = 0 (100% loss)
Approximate round trip time: min = 0ms, max = 0ms, avg = 0ms

PS C:\Users\thorsten.oeltjen> ping 10.40.61.10
Pinging <name>.<fqn> [192.168.61.1] with 32 bytes of data:
TimedOut
TimedOut
TimedOut
DestinationHostUnreachable

Ping statistics for <name>.<fqn>:
Packets: Sent = 4 Received = 0 (100% loss)
Approximate round trip time: min = 0ms, max = 0ms, avg = 0ms


PS C:\Users\> ping.exe 10.40.61.10
Ping wird ausgef?hrt f?r 10.40.61.10 mit 32 Bytes Daten:
Antwort von 10.40.61.10: Bytes=32 Zeit=14ms TTL=254
Antwort von 10.40.61.10: Bytes=32 Zeit=4ms TTL=254
DestinationHostUnreachable
(1)
RichardSiddaway
(1)
TargetHost
(1)
PingStatus
(1)
WmiObject
(1)
TimedOut
(1)
FunTest
(1)
Skriptsniplet
(1)
  RichS [MVP] replied to Thorsten A. Oeltjen
18-Mar-10 02:49 PM
is there a firewall setting on the remote machine that prevents pings and/or
WMI response?
--
Richard Siddaway
All scripts are supplied "as is" and with no warranty
PowerShell MVP
Blog and PowerShell User Group:
http://msmvps.com/blogs/RichardSiddaway/Default.aspx
  Thorsten A. Oeltjen replied to RichS [MVP]
19-Mar-10 01:49 AM
Am 18.03.2010 19:49, schrieb RichS [MVP]:
sorry - a firwall cannot be the reason, that a ping to an ip is resolved
to a name and than back to an other ip ... afaik.

and no - there is no firwall between the two hosts
  IT STAFF replied to Thorsten A. Oeltjen
19-Mar-10 05:03 AM
I have not got time to read the codes.

Can i ask a questions:

a) you ping a machine and the machine gives u an ip address
b) u ping the ip address using -a and it resolves to another hostname
instead of the original hostname ?
  Thorsten A. Oeltjen replied to IT STAFF
19-Mar-10 05:55 AM
Am 19.03.2010 10:03, schrieb IT STAFF:
a)
one thing i did:
ping-host 10.40.61.10

machine answers:
Pinging myservername.mydomain [192.168.61.1] with 32 bytes of data:

as i mentioned - we focused that there was an mistake in the dns server
who hold the second ip.

my question is about the powershell behavior ping ip_1 and getting an
result for ip_2


b) no not another hostname - an other ip adress and no i did an
ping-host not an ping -a.
  Thorsten A. Oeltjen replied to Thorsten A. Oeltjen
19-Mar-10 06:11 AM
finally i understood

so the problem was not powershell based - it was simply the wrong
entrance at the dns server. the second ip was not reachable because
it is held in an other segment. somehow someone (my machine?)
did not regard that i ask for ip_1 - still took ip_2 from the cache.

- close this please -

[rest deleted]
Create New Account
help
Word file, how can achieve this using PS language? Powershell Discussions Word (1) Siddaway (1) Richardsiddaway (1) Controllers (1) Tablehttp (1) Warranty (1) A table in Word. . . I cannot remember ever done in XML. . . Marco This shows how to create a table http: / / msmvps.com / blogs / richardsiddaway / archive / 2009 / 08 / 31 / word-add-a-table.aspx This shows how to add data to a table http: / / msmvps.com / blogs / richardsiddaway / archive / 2009 / 08 / 31 / word-add-a-table.aspx This gives a link for downloading the Word functions http: / / msmvps.com / blogs / richardsiddaway / archive / 2009 / 09 / 07 / word-module.aspx I presume you know how to get the Siddaway All scripts are supplied "as is" and with no warranty PowerShell MVP Blog: http: / / richardsiddaway.spaces.live.com / PowerShell User Group: http: / / www.get-psuguk.org.uk keywords: Domain, Controller
to toggle the read-only attribute of a file from a powershell script? Powershell Discussions Richardsiddaway (1) Powershell (1) Protect (1) Richard (1) Folder (1) Attribute (1) Grimshaw (1) Siddaway (1 Please note that all scripts are supplied "as is" and with no warranty Blog: http: / / richardsiddaway.spaces.live.com / PowerShell User Group: http: / / www.get-psuguk.org.uk Thanks Richard, that
tool? What do you think? Powershell Discussions PowerShell (1) DoversThank (1) Powergui (1) Scripts (1) Richardsiddaway (1) Responses (1) Software (1) Phoenix (1) First thing to remembe about powergui is that Please note that all scripts are supplied "as is" and with no warranty Blog: http: / / richardsiddaway.spaces.live.com / PowerShell User Group: http: / / www.get-psuguk.org.uk I use PowerGUI