Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

$ping.send(hostname) pings ipv6 instead of ipv4 address

433 views
Skip to first unread message

proxb

unread,
Nov 7, 2009, 2:51:39 PM11/7/09
to
I am having problems with my code working. For whatever reason it
tries to ping a hostname, it tries pinging an ipv6 address instead of
the ipv4 address, which is returning a status code of 11050 (General
Failure). Below is the relevant code. Anyone have an idea on how to
make it ping ipv4 instead of ipv6?

##
$ping = new-object System.Net.NetworkInformation.Ping
$reply = $ping.send("hostname")
Write-host "Ping code: $reply.status"

Ping code: 11050
##

I would imagine that there is a way to tell it what version of ip to
look at, much like you can while in the command prompt: ping hostname
-4 or ping hostname -6

Thanks for any help with this.

Boe

Martin Zugec

unread,
Nov 8, 2009, 9:04:20 AM11/8/09
to

Hi Boe,

you can use following code: $Ping = (Get-WmiObject -Query "Select StatusCode
from Win32_PingStatus where address = 'hostname'")

Martin

"proxb" <boe...@gmail.com> wrote in message
news:4c685174-1727-4de3...@b15g2000yqd.googlegroups.com...

proxb

unread,
Nov 8, 2009, 8:05:36 PM11/8/09
to
Thanks for the suggestion, however that still didn't work. For some
reason, it is still trying to come back as an ipv6 address. I am
running Windows 7 and just doing a test ping against my own local
machine. I've disabled ipv6 from my network properties, so I am not
sure why it is still attempting to ping from that address. I am still
trying to research this and see what I can find.

__GENUS : 2
__CLASS : Win32_PingStatus
__SUPERCLASS :
__DYNASTY :
__RELPATH :
__PROPERTY_COUNT : 1
__DERIVATION : {}
__SERVER :
__NAMESPACE :
__PATH :
StatusCode : 11050


On Nov 8, 8:04 am, "Martin Zugec" <martin.zu...@gmail.com> wrote:
> Hi Boe,
>
> you can use following code: $Ping = (Get-WmiObject -Query "Select StatusCode
> from Win32_PingStatus where address = 'hostname'")
>
> Martin
>

> "proxb" <boep...@gmail.com> wrote in message

Martin Zugec

unread,
Nov 9, 2009, 2:57:09 AM11/9/09
to
And if you run ping.exe, do you get IPv4 or IPv6? ;)

Martin

"proxb" <boe...@gmail.com> wrote in message

news:c31cfb6d-b74a-4e61...@b15g2000yqd.googlegroups.com...

proxb

unread,
Nov 9, 2009, 8:09:42 AM11/9/09
to
I get an ipv6 address. I have to use the "-4" switch with Ping in
order for it to ping the hostname for the ipv4 address. I didn't know
if there was a way in powershell to make it look for the ipv4 address
vs ipv6.

On Nov 9, 1:57 am, "Martin Zugec" <martin.zu...@gmail.com> wrote:
> And if you run ping.exe, do you get IPv4 or IPv6? ;)
>
> Martin
>

> >> > Boe- Hide quoted text -
>
> - Show quoted text -

RichS [MVP]

unread,
Nov 12, 2009, 4:36:07 PM11/12/09
to
Have you tried putting the IP address in and see if it works

I did this

PS> $ping = New-Object -TypeName System.Net.NetworkInformation.Ping
PS> $reply = $ping.Send("127.0.0.1")
PS> $reply


Status : Success
Address : 127.0.0.1
RoundtripTime : 0
Options : System.Net.NetworkInformation.PingOptions
Buffer : {97, 98, 99, 100...}

which suggests it works on IP4 OK

I couldn't find an option to set IP 4 or IP6
--
Richard 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


"proxb" wrote:

> .
>

Herb Martin

unread,
Feb 4, 2010, 4:20:08 PM2/4/10
to

I don't know if this suggestion is of much value
but it is something that I would do were this to
happen to me:

Try doing an NSLookup (against your host name)
and see what comes back...(just curious before I
would get to deep in troubleshooting.)

"RichS [MVP]" <Rich...@discussions.microsoft.com> wrote in message
news:47392F7F-2180-4D26...@microsoft.com...

0 new messages