Jump to content

Ping certain ports


Recommended Posts

how would i ping a server on a certain port like port: 1234 or 5467

something other then default port. Thanks to whoever helps.

Lookup the TCP functions in the help file; pay attention to TCPConnect() and then calculate your times, etc, based off of TIMIERINIT. That's one option; the other option is to search the forum for threads for pinging. There are TONS of these types of scripts out there.

-_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë 맧ëñ§ë øƒ !ïƒë.

Link to comment
Share on other sites

Im not too great at networking, but I thought ping packets were always sent to the same port, similar to the way email and browsers always use the same port.

"You can't ping a port as ping and TCP operate at different layers.

You could however download a port scanner and scan for the port in question - that would seem to achieve the thing you're looking for.

Port scanners are two a penny so just Goggle for port scanner and you'll be spoilt for choice."

- http://www.tek-tips.com/viewthread.cfm?qid...8343&page=1

Quick google search :)

Edited by crzftx
Link to comment
Share on other sites

Im not too great at networking, but I thought ping packets were always sent to the same port, similar to the way email and browsers always use the same port.

"You can't ping a port as ping and TCP operate at different layers.

You could however download a port scanner and scan for the port in question - that would seem to achieve the thing you're looking for.

Port scanners are two a penny so just Goggle for port scanner and you'll be spoilt for choice."

- http://www.tek-tips.com/viewthread.cfm?qid...8343&page=1

Quick google search :)

No, you are correct; but you CAN use the TCP functions of autoit to:

1. Start the timer

2. Connect to the server w/ the specified port

2a. If bad ip, return

2b. If bad port, return

2c. If bad connection, return

3. Calculate time difference in the conection

4. Kill connection

5. Display time

As long as you are not making hundreds/thousands of requests per minute, etc, then there is no reason why this method couldn't be used to ascertain if a certain port on a certain server is online :(

-_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë 맧ëñ§ë øƒ !ïƒë.

Link to comment
Share on other sites

This should do it, I think.

Func _PingPort($ip, $port)
    ; Connect to server
    $nSock = TCPConnect($ip, $port)
    if ($nSock <= -1) Then return -1
        
    ; Fill up 32 bytes
    $sBytes = ""
    For $i = 1 to 32
        $sBytes &= " "
    Next
    
    $nTimer = TimerInit()
    
    ; Send the 32 bytes to the server
    $nSent = TCPSend($nSock, $sBytes)
    if (@error or $nSent <= 0) then Return -1
    
    $nTimerDiff = TimerDiff($nTimer)
    
    TCPCloseSocket($nSock)
    
    Return $nTimerDiff
EndFunc


TCPStartup()
MsgBox(0, "", _PingPort("64.233.187.99", 80))
TCPShutdown()
Edited by cppman
Link to comment
Share on other sites

This should do it, I think.

Func _PingPort($ip, $port)
    ; Connect to server
    $nSock = TCPConnect($ip, $port)
    if ($nSock <= -1) Then return -1
        
    ; Fill up 32 bytes
    $sBytes = ""
    For $i = 1 to 32
        $sBytes &= " "
    Next
    
    $nTimer = TimerInit()
    
    ; Send the 32 bytes to the server
    $nSent = TCPSend($nSock, $sBytes)
    if (@error or $nSent <= 0) then Return -1
    
    $nTimerDiff = TimerDiff($nTimer)
    
    TCPCloseSocket($nSock)
    
    Return $nTimerDiff
EndFunc


TCPStartup()
MsgBox(0, "", _PingPort("64.233.187.99", 80))
TCPShutdown()
Yeah, But i'm not even sure if a send is actually required; just the connection.

$ip = "12.129.225.125"
$port = 3724
TCPStartup()
$start = TimerInit()
$sock = TCPConnect($ip, $port)
If @error = 1 Then
    ConsoleWrite("Invalid IP" & @CRLF)
    Exit
ElseIf @error = 2 Then
    ConsoleWrite("Invalid Port" & @CRLF)
    Exit
ElseIf $sock = -1 Then
    ConsoleWrite("Invalid connection" & @CRLF)
    Exit
Else
    $stop = TimerDiff($start)
    ConsoleWrite("Took:  "&$stop&"ms to return" & @CRLF)
    TCPCloseSocket($sock)
EndIf

Just the time it takes to create the connection should be sufficient enough to find if the port is open/closed and your latency to it.

Edited by zackrspv

-_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë 맧ëñ§ë øƒ !ïƒë.

Link to comment
Share on other sites

Good little GUI program i wrote for this purpose:

Note: You can use hostnames (google.com, http://google.com, http://www.google.com) and it will work too.

#include<GUIConstantsEx.au3>
$sock = ""
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 328, 447, 193, 125)
$IPin = GUICtrlCreateInput("", 50, 0, 121, 21)
GUICtrlCreateLabel("IP/Host:", 0, 0, 50, 17)
$History = GUICtrlCreateEdit("", 2, 82, 321, 361)
$Go = GUICtrlCreateCheckbox("Start", 250, -2, 75, 25, 0)
GUICtrlSetBkColor(-1, 0x009933)
GUICtrlCreateLabel("Port", 178, 2, 23, 17)
$Portin = GUICtrlCreateInput("", 204, 0, 45, 21)
GUICtrlCreateLabel("History", 2, 62, 36, 17)
$Gstatus = GUICtrlCreateLabel("", 74, 30, 196, 41)
GUICtrlSetFont(-1, 26, 400, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)
#EndRegion ### START Koda GUI section ### Form=
TCPStartup()

While 1
    $msgb = GUIGetMsg()
    Switch $msgb
        Case $GUI_EVENT_CLOSE
            TCPCloseSocket($sock)
            TCPShutdown()
            Exit

        Case BitAND(GUICtrlRead($go),$GUI_CHECKED)
    
        Case BitAND(GUICtrlRead($go),$GUI_UNCHECKED)
            $ip = GUICtrlRead($IPin, 1)
            $port = GUICtrlRead($Portin, 1)
            If $ip = "" Or $port = "" Then
            Else
                $ip = TCPNameToIP($ip)
                Sleep(1000)
                $start = TimerInit()
                $sock = TCPConnect($ip, $port)
                If @error = 1 Then
                    MsgBox(0, "Error", "Invalid IP entered!")
                    GUICtrlSetState($go, $GUI_UNCHECKED)
                ElseIf @error = 2 Then
                    MsgBox(0, "Error", "Invalid/closed Port entered!")
                    GUICtrlSetState($go, $GUI_UNCHECKED)
                ElseIf $sock = -1 Then
                    GUICtrlSetData($Gstatus, "OFFLINE!")
                    GUICtrlSetFont($gstatus, 26)
                    GUICtrlSetColor($gstatus, 0xFF0093)
                    GUICtrlSetData($History, "[" & @HOUR & ":" & @MIN & ":" & @SEC & "] OFFLINE, "&$ip&":"&$port & @CRLF, GUICtrlRead($History))
                Else
                    $Stop = Round(TimerDiff($start), 2)
                    GUICtrlSetData($Gstatus, "ONLINE!")
                    GUICtrlSetFont($gstatus, 26)
                    GUICtrlSetColor($gstatus, 0x009933)
                    GUICtrlSetData($History, "[" & @HOUR & ":" & @MIN & ":" & @SEC & "] ONLINE, "&$ip&":"&$port&" ms:" & $Stop & @CRLF, GUICtrlRead($History))
                    TCPCloseSocket($sock)
                EndIf
            EndIf
    EndSwitch
WEnd

Nothing special lol. You can adapt it to disable the $IPIN and $PORTIN when the Go box is checked, otherwise you can change the values inline and see inline results. Heck you can even change the refresh speed if ya want :)

Edited by zackrspv

-_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë 맧ëñ§ë øƒ !ïƒë.

Link to comment
Share on other sites

Good little GUI program i wrote for this purpose:

Note: You can use hostnames (google.com, http://google.com, http://www.google.com) and it will work too.

#include<GUIConstantsEx.au3>
$sock = ""
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 328, 447, 193, 125)
$IPin = GUICtrlCreateInput("", 50, 0, 121, 21)
GUICtrlCreateLabel("IP/Host:", 0, 0, 50, 17)
$History = GUICtrlCreateEdit("", 2, 82, 321, 361)
$Go = GUICtrlCreateCheckbox("Start", 250, -2, 75, 25, 0)
GUICtrlSetBkColor(-1, 0x009933)
GUICtrlCreateLabel("Port", 178, 2, 23, 17)
$Portin = GUICtrlCreateInput("", 204, 0, 45, 21)
GUICtrlCreateLabel("History", 2, 62, 36, 17)
$Gstatus = GUICtrlCreateLabel("", 74, 30, 196, 41)
GUICtrlSetFont(-1, 26, 400, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)
#EndRegion ### START Koda GUI section ### Form=
TCPStartup()

While 1
    $msgb = GUIGetMsg()
    Switch $msgb
        Case $GUI_EVENT_CLOSE
            TCPCloseSocket($sock)
            TCPShutdown()
            Exit

        Case BitAND(GUICtrlRead($go),$GUI_CHECKED)
    
        Case BitAND(GUICtrlRead($go),$GUI_UNCHECKED)
            $ip = GUICtrlRead($IPin, 1)
            $port = GUICtrlRead($Portin, 1)
            If $ip = "" Or $port = "" Then
            Else
                $ip = TCPNameToIP($ip)
                Sleep(1000)
                $start = TimerInit()
                $sock = TCPConnect($ip, $port)
                If @error = 1 Then
                    MsgBox(0, "Error", "Invalid IP entered!")
                    GUICtrlSetState($go, $GUI_UNCHECKED)
                ElseIf @error = 2 Then
                    MsgBox(0, "Error", "Invalid/closed Port entered!")
                    GUICtrlSetState($go, $GUI_UNCHECKED)
                ElseIf $sock = -1 Then
                    GUICtrlSetData($Gstatus, "OFFLINE!")
                    GUICtrlSetFont($gstatus, 26)
                    GUICtrlSetColor($gstatus, 0xFF0093)
                    GUICtrlSetData($History, "[" & @HOUR & ":" & @MIN & ":" & @SEC & "] OFFLINE, "&$ip&":"&$port & @CRLF, GUICtrlRead($History))
                Else
                    $Stop = Round(TimerDiff($start), 2)
                    GUICtrlSetData($Gstatus, "ONLINE!")
                    GUICtrlSetFont($gstatus, 26)
                    GUICtrlSetColor($gstatus, 0x009933)
                    GUICtrlSetData($History, "[" & @HOUR & ":" & @MIN & ":" & @SEC & "] ONLINE, "&$ip&":"&$port&" ms:" & $Stop & @CRLF, GUICtrlRead($History))
                    TCPCloseSocket($sock)
                EndIf
            EndIf
    EndSwitch
WEnd

Nothing special lol. You can adapt it to disable the $IPIN and $PORTIN when the Go box is checked, otherwise you can change the values inline and see inline results. Heck you can even change the refresh speed if ya want :)

exactly what i needed. thanks very much!

"The quieter you are, the more you are able to hear..."

My AppsUSB Finder

Link to comment
Share on other sites

  • 5 months later...

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