Jump to content

Ping not working across subnet


Recommended Posts

I'm working with the built-in Ping function, and it seems to ping computers on my own subnet just fine, but it fails to ping any computer on a different subnet. I can ping those same computers from the command line just fine. Is this by design, and is there anything I can do about it?

Thanks!

Link to comment
Share on other sites

$pingtest = Ping(StringTrimLeft($hosts, 2))
MsgBox(0, "show error", @error)
If $pingtest <> 0 Then
    Run("explorer.exe /root," & $hosts & "\c$")
    Else
    MsgBox(0, "Computer unavailable", "Unable to connect to the computer you requested. The computer may be off...")
EndIf

I'm not sure how to upload an image (image button just asks for a link), but the command line is as follows:

C:WindowsSystem32>ping 01055w7
 
Pinging 01055w7.domain.com [10.21.31.124] with 32 bytes of data:
Reply from 10.21.31.124: bytes=32 time=1ms TTL=127
Reply from 10.21.31.124: bytes=32 time=3ms TTL=127
Reply from 10.21.31.124: bytes=32 time=1ms TTL=127
Reply from 10.21.31.124: bytes=32 time=1ms TTL=127
 
Ping statistics for 10.21.31.124:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 1ms, Maximum = 3ms, Average = 1ms
Edited by OneJeremias
Link to comment
Share on other sites

  • Developers

You need to specify the total host name when using ping and not expect that the domain search suffix is applied automatically.

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

That seems to break it completely. To clarify what I changed:

Old method (worked within my own subnet): Ping("01055w7") where 01055w7 is the host name of the computer to ping.

Your method (@ error now set to 4 every time): Ping("01055w7.domain.com")

Full disclosure: I am passing Ping a string in this manner: Ping(StringTrimLeft("01055w7.domain.com", 2), because I have a function that returns the computer name. The change I made was to that function, which now appends .domain.com to the end. As I said though, Ping works if I do NOT append .domain.com to the end.

Update: I was just doing some more playing around, and noticed that today the @error is coming back as 0. I checked what Ping is returning, and it is also 0. I thought @error was supposed to be set to non-zero if Ping returned 0?

Edited by OneJeremias
Link to comment
Share on other sites

  • Developers

this:

ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : Ping(StringTrimLeft("\\01055w7.domain.com", 2)) = ' & Ping(StringTrimLeft("\\01055w7.domain.com", 2)) & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : StringTrimLeft("\\01055w7.domain.com", 2) = ' & StringTrimLeft("\\01055w7.domain.com", 2) & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console

Returns:

@@ Debug(1) : Ping(StringTrimLeft("\\01055w7.domain.com", 2)) = 149
>Error code: 0
@@ Debug(2) : StringTrimLeft("\\01055w7.domain.com", 2) = 01055w7.domain.com
>Error code: 0

So seems to work fine.

Jos

Edited by Jos
removed real domain on request

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • 6 months later...

Finally getting back to this project after a long hiatus. Just as an FYI to anyone else who may be having this problem:

Jos was spot on in his help above. My host name had an additional space at the end of the string that I didn't see until I tried to append my domain name to the end and outputted to a msgbox. Doh. :-)

Thanks Jos!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...