Windows Vista Forums

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


    proxb Guest

    $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

  2. #2


    Martin Zugec Guest

    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

    > 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

  3. #3


    RichS [MVP] Guest

    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:

    > 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

  4. #4


    Herb Martin Guest

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

    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]" <RichSMVP@newsgroup> wrote in message
    news:47392F7F-2180-4D26-80CC-3FE033073CA6@newsgroup

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

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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
IPv4 and ipv6 not connected dw999 Network & Sharing 4 05 Nov 2010
I can ping with IPv6. I can not ping with IPv4. Eric Gamess Vista General 3 08 Jan 2009
Switch the Pinging from IPv6 to Ping IPv4 VistaKing Network & Sharing 2 07 Oct 2008
Cannot access/ping ipv4 address dcb Vista networking & sharing 4 08 Jan 2008
Wireless N cards do both IPv4 and IPv6? Why? Don Kallman Vista networking & sharing 2 29 Aug 2007