Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

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

Reply
 
Old 2 Weeks Ago   #1 (permalink)
proxb


 
 

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

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

My System SpecsSystem Spec
Old 2 Weeks Ago   #2 (permalink)
Martin Zugec


 
 

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

Hi Boe,

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

Martin

"proxb" <boeprox@newsgroup> wrote in message
news:4c685174-1727-4de3-9572-df3d6b4bf70a@newsgroup
Quote:

> 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
My System SpecsSystem Spec
Old 2 Weeks Ago   #3 (permalink)
RichS [MVP]


 
 

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

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:
Quote:

> 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
> .
>
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
IPv4 and ipv6 not connected Network & Sharing
I can ping with IPv6. I can not ping with IPv4. Vista General
Switch the Pinging from IPv6 to Ping IPv4 Network & Sharing
Cannot access/ping ipv4 address Vista networking & sharing
Wireless N cards do both IPv4 and IPv6? Why? Vista networking & sharing


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46