nullschritt Posted July 1, 2013 Share Posted July 1, 2013 (edited) 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 July 1, 2013 by nullschritt Link to comment Share on other sites More sharing options...
mrflibblehat Posted July 1, 2013 Share Posted July 1, 2013 (edited) 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 July 1, 2013 by mrflibblehat nullschritt 1 [font="'courier new', courier, monospace;"]Pastebin UDF | Prowl UDF[/font] Link to comment Share on other sites More sharing options...
nullschritt Posted July 2, 2013 Author Share Posted July 2, 2013 Works great! thanks! Link to comment Share on other sites More sharing options...
guinness Posted July 2, 2013 Share Posted July 2, 2013 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 parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
UEZ Posted July 2, 2013 Share Posted July 2, 2013 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
nullschritt Posted July 2, 2013 Author Share Posted July 2, 2013 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. (: Link to comment Share on other sites More sharing options...
Solution nullschritt Posted July 2, 2013 Author Solution Share Posted July 2, 2013 (edited) 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 EndFuncand 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 July 2, 2013 by nullschritt mrflibblehat 1 Link to comment Share on other sites More sharing options...
nullschritt Posted July 2, 2013 Author Share Posted July 2, 2013 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! Link to comment Share on other sites More sharing options...
mrflibblehat Posted July 3, 2013 Share Posted July 3, 2013 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] Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now