Jump to content

Pinging another computer?


Shyke
 Share

Recommended Posts

Function Reference

Ping Pings a host and returns the roundtrip-time.

Ping ( address or hostname [, timeout] )

Parameters

address/hostnameCan be i.e. "www.hiddensoft.com" or "178.50.76.4".timeout[optional] Is the time to wait for an answer in milliseconds (default is 4000).

Return Value

Success:Returns the roundtrip-time in milliseconds ( greater than 0 ).Failure:Returns 0 if host is not pingable or other network errors occured and sets @error. (See Remarks)

Remarks

When the function fails (returns 0) @error contains extended information:

1 = Host is offline

2 = Host is unreachable

3 = Bad destination

4 = Other errors

Related

None.

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Thank-you, I am trying to make a program so users can see if my server is up or not.

THANKS!

EDIT:

I still can't ping my server, I get error 1 back... try pinging " xxxxxxxxxxxxx "...

Why can't i ping my server but i can ping google?

EDIT: I got it workin, ok, thanks!

Edited by Shyke
Link to comment
Share on other sites

This may be more than you need, but I made a simple program to Ping certain locations... Comes in handy every now and then.

; ----------------------------------------------------------------------------
;
; AutoIt Version: 3.1.0
; Author:        Ryan <rpm91m@gmail.com>
;
; script made to check ip's and see what their status is
;
;
; ----------------------------------------------------------------------------
; Script Start - Add your code below here

#include <GUIConstants.au3>
Global $publicIP
Global $listips
GetPublicIP ()
$main = GUICreate("PingMe", 400, 400)
;$ico = FileInstall("PingMeIcon.ico", @TempDir)
;GUISetIcon(@TempDir & "\PingMeIcon.ico")
$menu = GUICtrlCreateMenu("File")
$item = GUICtrlCreateMenuItem("Ping address...", $menu)
$item2 = GUICtrlCreateMenuItem("Exit", $menu)
$menu2 = GUICtrlCreateMenu("Help")
$menu2item = GUICtrlCreateMenuItem("About", $menu2)
$listips = GUICtrlCreateListView("Ip's/Hostanmes | Roundtrip in Miliseconds | Extended Info.", 5, 10, 330, 200)
$addinp = GUICtrlCreateInput("", 10, 270, 200, 20)
$addinp2 = GUICtrlCreateInput("", 10, 320, 200, 20)
$addbut = GUICtrlCreateButton("Add IP/Hostname", 240, 287, 100, 30)
$menu3 = GUICtrlCreateMenu("My IP's")
$menu3item = GUICtrlCreateMenuItem("IP 1: " & @IPAddress1, $menu3)
$menu3item2 = GUICtrlCreateMenuItem("IP 2: " & @IPAddress2, $menu3)
$menu3item3 = GUICtrlCreateMenuItem("IP 3: " & @IPAddress3, $menu3)
$menu3item4 = GUICtrlCreateMenuItem("IP 4: " & @IPAddress4, $menu3)
$menu3item5 = GUICtrlCreateMenuItem("Public IP: " & $publicIP, $menu3)
$styles = GUICtrlCreateMenu("Methods")
$stylesitem = GUICtrlCreateMenuItem("Batch File Style", $styles)
$del = GUICtrlCreateButton("Delete selected address", 240, 250)
GUICtrlCreateLabel("IP/Hostname: ", 10, 246)
GUICtrlCreateLabel("Time to wait for ping response in miliseconds: ", 10, 296)
$opt = GUICtrlCreateLabel("Optional", 10, 340)
GUICtrlSetFont($opt, 9, 3, 400, "Comic Sans MS")
GUICtrlSetFont($addbut, 8)
GUISetState()
Func MainLoop()
   While 1
      $get = GUIGetMsg()
      Select
         Case $get = -3
            FileDelete("publicIP.tmp")
            FileDelete("BatchFileStyle.bat")
            Exit
         Case $get = $item2
            Exit
         Case $get = $item
            $ip = InputBox("IP/Hostname", "Please enter an IP address or a hostname: ")
            If @error Then ContinueLoop
            $mili = InputBox("Ping time", "Time to wait for an answer from the provided IP/Hostname in miliseconds (1000 Miliseconds= 1 second): ")
            If @error Then ContinueLoop
            $ping = Ping($ip, Number($mili))
            If Not @error Then
               GUICtrlCreateListViewItem($ip & "|" & $ping & "|" & "Sucess", $listips)
            ElseIf @error Then
               GUICtrlCreateListViewItem($ip & "|" & $ping & "|" & "Unknown error", $listips)
            ElseIf $ping = 0 Then
               GUICtrlCreateListViewItem($ip & "|" & $ping & "|" & "Not pingable", $listips)
            ElseIf @error = 1 Then
               GUICtrlCreateListViewItem($ip & "|" & $ping & "|" & "Host offline", $listips)
            ElseIf @error = 2 Then
               GUICtrlCreateListViewItem($ip & "|" & $ping & "|" & "Host unreachable", $listips)
            ElseIf @error = 3 Then
               GUICtrlCreateListViewItem($ip & "|" & $ping & "|" & "Bad destination", $listips)
            ElseIf @error = 4 Then
               GUICtrlCreateListViewItem($ip & "|" & $ping & "|" & "Other errors", $listips)
            EndIf
         Case $get = $menu2item
            MsgBox(4096, "About", "PingMe v 1.0.0 BETA is bought to you by Ryan <rpm91m at gmail dot com>" & @CRLF & "The final date of the project was 3/02/05" & @CRLF & "And remember! 1,000 Miliseconds is 1 second!" & @CRLF & "PingMe was created with AutoIt v. 3.1.0")
         Case $get = $addbut
            $ping2 = Ping(GUICtrlRead($addinp), Number(GUICtrlRead($addinp2)))
            If Not @error Then
               GUICtrlCreateListViewItem(GUICtrlRead($addinp) & "|" & $ping2 & "|" & "Sucess", $listips)
            ElseIf @error Then
               GUICtrlCreateListViewItem(GUICtrlRead($addinp) & "|" & $ping2 & "|" & "Unknown error", $listips)
            ElseIf $ping2 = 0 Then
               GUICtrlCreateListViewItem(GUICtrlRead($addinp) & "|" & $ping2 & "|" & "Not pingable", $listips)
            ElseIf @error = 1 Then
               GUICtrlCreateListViewItem(GUICtrlRead($addinp) & "|" & $ping2 & "|" & "Host offline", $listips)
            ElseIf @error = 2 Then
               GUICtrlCreateListViewItem(GUICtrlRead($addinp) & "|" & $ping2 & "|" & "Host unreachable", $listips)
            ElseIf @error = 3 Then
               GUICtrlCreateListViewItem(GUICtrlRead($addinp) & "|" & $ping2 & "|" & "Bad destination", $listips)
            ElseIf @error = 4 Then
               GUICtrlCreateListViewItem(GUICtrlRead($addinp) & "|" & $ping2 & "|" & "Other errors", $listips)
            EndIf
         Case $get = $menu3item
            GUICtrlSetData($addinp, "", "")
            GUICtrlSetData($addinp, @IPAddress1, 1)
         Case $get = $menu3item2
            GUICtrlSetData($addinp, "", "")
            GUICtrlSetData($addinp, @IPAddress2, 1)
         Case $get = $menu3item3
            GUICtrlSetData($addinp, "", "")
            GUICtrlSetData($addinp, @IPAddress3, 1)
         Case $get = $menu3item4
            GUICtrlSetData($addinp, "", "")
            GUICtrlSetData($addinp, @IPAddress4, 1)
         Case $get = $menu3item5
            GUICtrlSetData($addinp, "", "")
            GUICtrlSetData($addinp, $publicIP, 1)
         Case $get = $del
            GUICtrlDelete(GUICtrlRead($listips))
         Case $get = $stylesitem
            BatchFileStyle ()
      EndSelect
   WEnd
EndFunc;==>MainLoop 
MainLoop()

Func GetPublicIP ()
   ProgressOn("Getting IP...", "Getting the public IP address needed...")
   InetGet("http://www.whatismyip.org", "publicIP.tmp")
   ProgressSet(25)
   $publicIP = FileReadLine("publicIP.tmp")
   ProgressSet(50)
   ProgressSet(75)
   FileDelete("publicip.tmp")
   ProgressSet(100)
   ProgressOff()
EndFunc;==>GetPublicIP 

Func BatchFileStyle ()
   $ip = InputBox("IP/Hostname", "Please enter an IP address or hostname to ping:")
   If @error Then MainLoop()
   $milisecs = InputBox("Time", "Please enter the amount of miliseconds to wait for a response: ")
   If @error Then MainLoop()
   FileWriteLine("BatchFileStyle.bat", "title BatchFileStyle by PingMe")
   FileWriteLine("BatchFileStyle.bat", "echo off")
   FileWriteLine("BatchFileStyle.bat", "cls")
   FileWriteLine("BatchFileStyle.bat", "Ping " & $ip & " -w " & $milisecs)
   FileWriteLine("BatchFileStyle.bat", "pause")
   Run("BatchFileStyle.bat")
   WinWait("BatchFileStyle by PingMe")
   WinWaitClose("BatchFileStyle by PingMe")
   FileDelete("BatchFileStyle.bat")
   MainLoop()
EndFunc;==>BatchFileStyle
Edited by layer
FootbaG
Link to comment
Share on other sites

This may be more than you need, but I made a simple program to Ping certain locations... Comes in handy every now and then.

Layer- Nice job! I learned a lot from your code. It would be nice to have a "Refresh" button as well...

;)

...by the way, it's pronounced: "JIF"... Bob Berry --- inventor of the GIF format
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...