Sign in to follow this  
Followers 0
nullschritt

[UDF] _checkport() See if a port is accessible to the internet.

1 post in this topic

#1 ·  Posted (edited)

Func _CheckPort($vPort = 7337)

TCPStartup()

    $MainSocket = TCPListen('0.0.0.0', $vPort)
    FileDelete(@ScriptDir & "\port.dat")
    Local $hDownload, $go = 1

    Do
        Local $ConnectedSocket = TCPAccept($MainSocket)
        If $ConnectedSocket >= 0 Then
            TCPSend($connectedsocket, "Cool Story Bro")
        EndIf

        Sleep(5)
    
        if $go = 1 then 
            $hDownload = InetGet("http://prodynamicsinc.com/link.php?CMD=page&ID=portcheck&buffer=0&port=" & $vPort&"&IP="&_GetIP(), @ScriptDir & "\port.dat", 1, 1)
            $go = 0
        EndIf
        
    Until InetGetInfo($hDownload, 2)

    local $portcheck = FileRead(@ScriptDir & "\port.dat")
    FileDelete(@ScriptDir & "\port.dat")
    InetClose($hDownload)
    TCPShutdown()
    
        If $portcheck = "Port Open" Then
            Return True
        Else
            Return False
        EndIf
EndFunc
and the sourcecode of the php page:

<?PHP
echo getserverstatus($_GET['IP'],$_GET['port']);
die();
function GetServerStatus($site, $port)
{
$status = array("Port Not Open", "Port Open");
$fp = @fsockopen($site, $port, $errno, $errstr, 2);
if (!$fp) {
    return $status[0];
} else
  { return $status[1];}
}
?>
Cheers.

Credit to mrflibblehat for the original idea.

Edited by nullschritt

Share this post


Link to post
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
Sign in to follow this  
Followers 0