Jump to content
Sign in to follow this  
nullschritt

Check if port is open to WAN

Recommended Posts

nullschritt

Hello, I need to check if a port is open to wan or not, for a P2P messenger I am developing, I was able to write up a small snipplet of code that should work, but seems to always return 1 even if the port is not open over WAN(forwarded).

 

Anyone take a gander at what I'm doing wrong?

func _checkport($port = 71337)
$test = UDPBind("0.0.0.0", $port)
$ip = _GetIP()
$socket = UDPOpen($ip, $port)
If $socket[0] <> 0 Then
return 1
Else
Return 0
EndIf
UDPCloseSocket($test)
UDPCloseSocket($socket)
EndFunc
Edited by nullschritt

Share this post


Link to post
Share on other sites
mrflibblehat

That wont work as you are still testing from behind your internal router.

Try this.

Func _CheckPort($vPort = 80)
    $vUrl = InetRead("http://flibware.com/port.php?port=" & $vPort)
    $vCheckPort = StringRegExp(BinaryToString($vUrl), "<body>(.*?)</body></html>", 3)
        If $vCheckPort[0] = "Port Open" Then
            Return True
        Else
            Return False
        EndIf
EndFunc

This will test from a remote website

Edited by mrflibblehat
  • Like 1

[font="'courier new', courier, monospace;"]Pastebin UDF | Prowl UDF[/font]

Share this post


Link to post
Share on other sites
nullschritt

Works great! thanks!

Share this post


Link to post
Share on other sites
guinness

mrflibblehat forgot to mention that's his personal website, so they reserve the rights.


UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites
UEZ

Can you try this whether it is working? -> 

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
nullschritt

mrflibblehat forgot to mention that's his personal website, so they reserve the rights.

Once I realized this, I wrote a php function that acts simmilar to his, to host myself. (:

Share this post


Link to post
Share on other sites
nullschritt

Here's my modified code:

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.

 

Edit: Edited function to allow listening on incoming socket, and response, while awaiting a response on status of the port being checked.

Edit Edit: It still doesn't seem to work, it works for ports opened by other applications, but for some reason it's not letting me check if a port has been opened within the same script....

Edit Edit Edit: Nevermind on that last, seems to work perfect, the port I had defaulted was out of range.

Edited by nullschritt
  • Like 1

Share this post


Link to post
Share on other sites
nullschritt

Can you try this whether it is working? -> 

Br,

UEZ

Sorry but it looks a little heavy for my use, I really only need to check one port, and also start a server on said port beforehand, thanks for the response though, much appreciated!

Share this post


Link to post
Share on other sites
mrflibblehat

Just to add,

If you want me to send my PHP script to you its freely available, Just drop me a PM. 


[font="'courier new', courier, monospace;"]Pastebin UDF | Prowl UDF[/font]

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.