Jump to content

TCPConnect won't return error when offline


Slym
 Share

Recommended Posts

Hi there,

I've made a little tool to easily "ping" a TCP port called PingPort but I have a bug or I'm doing something wrong.

You can download it (sources are included) using this link.

An easy way to understand my issue is to run pingport google.com:80

If you are connected then disconnect the cable or WiFi while pinging it will continue pinging successfully !?!

I don't understand why TCPConnect does not fail. Am I missing something here ?

Here is a piece of code :

TCPCloseSocket($socket)
  $timer = TimerInit()
  $socket = TCPConnect($server_ip, $protocol_port)
  If $socket = -1 OR @error Then
   ConsoleWrite($server_name & " is DOWN on port " & $protocol_port & GetErrorDescription(@error) & @CRLF)
  Else
   ConsoleWrite($server_name & " is UP on port " & $protocol_port & " - latency : " & HumanTime(TimerDiff($timer)) & @CRLF)
  EndIf
  Sleep(1000)
WEnd
TCPCloseSocket($socket)

Thank you for your help and time.

--------------------- [font="Franklin Gothic Medium"]LinuxLive USB Creator[/font], [size="3"]The only Linux Live USB creator with easy integrated virtualization (made with AutoIT)[/size] ---------------------

Link to comment
Share on other sites

What happens if you add TCPStartup?

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

Link to comment
Share on other sites

Is someone able to reproduce this bug or is it just on my computer ?

Here is a short code to reproduce it easily :

Just run it and disconnect your cable/wifi.

$protocol_port = 80
$server_ip = "209.85.229.104"
HotKeySet("{ESC}", "Terminate")

While 1
  $timer = TimerInit()
  TCPStartup()
  $socket = TCPConnect($server_ip, $protocol_port)
  ConsoleWrite("TCPConnect socket=" & $socket & " - @error=" & @error & @CRLF)
  If $socket = -1 Or @error Then
    ConsoleWrite($server_ip & " is DOWN on port " & $protocol_port & @CRLF)
  Else
    TCPCloseSocket($socket)
    ConsoleWrite($server_ip & " is UP on port " & $protocol_port & " - latency : " & Round(TimerDiff($timer), 3) & "ms" & @CRLF)
  EndIf
  TCPShutdown()
  Sleep(1000)
WEnd
Exit

Func Terminate()
  TCPShutdown()
  Exit
EndFunc   ;==>Terminate
Edited by Slym

--------------------- [font="Franklin Gothic Medium"]LinuxLive USB Creator[/font], [size="3"]The only Linux Live USB creator with easy integrated virtualization (made with AutoIT)[/size] ---------------------

Link to comment
Share on other sites

The code in your first post (linking to the program) isn't what I would call a good reproducer and neither is the small snippet that doesn't work. If you can consolidate this into a simple reproducer then I or someone else can test without having to debug a whole program.

Edited by guinness

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

Link to comment
Share on other sites

That's better. When I disconnected it stopped right away so I'm not following what your problem is, does the output help you?

Output:

TCPConnect socket=396 - @error=0

209.85.229.104 is UP on port 80 - latency : 51.88ms

TCPConnect socket=384 - @error=0

209.85.229.104 is UP on port 80 - latency : 58.466ms

TCPConnect socket=380 - @error=0

209.85.229.104 is UP on port 80 - latency : 51.53ms

TCPConnect socket=376 - @error=0

209.85.229.104 is UP on port 80 - latency : 52.327ms

TCPConnect socket=-1 - @error=10065

209.85.229.104 is DOWN on port 80

TCPConnect socket=-1 - @error=10065

209.85.229.104 is DOWN on port 80

TCPConnect socket=-1 - @error=10065

209.85.229.104 is DOWN on port 80

TCPConnect socket=-1 - @error=10065

209.85.229.104 is DOWN on port 80

TCPConnect socket=-1 - @error=10065

209.85.229.104 is DOWN on port 80

TCPConnect socket=-1 - @error=10065

209.85.229.104 is DOWN on port 80

TCPConnect socket=-1 - @error=10065

209.85.229.104 is DOWN on port 80

TCPConnect socket=-1 - @error=10065

209.85.229.104 is DOWN on port 80

TCPConnect socket=-1 - @error=10065

209.85.229.104 is DOWN on port 80

TCPConnect socket=-1 - @error=10065

209.85.229.104 is DOWN on port 80

TCPConnect socket=-1 - @error=10065

209.85.229.104 is DOWN on port 80

TCPConnect socket=-1 - @error=10065

209.85.229.104 is DOWN on port 80

TCPConnect socket=-1 - @error=10065

209.85.229.104 is DOWN on port 80

TCPConnect socket=-1 - @error=10065

209.85.229.104 is DOWN on port 80

TCPConnect socket=-1 - @error=10065

209.85.229.104 is DOWN on port 80

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

Link to comment
Share on other sites

Okay so it looks like it's related to my PC. It's like something is proxying requests because latency are also always very low (millisec). When I ping the same address, real latencies are quite high (1000ms or so).

Do you have any idea of what could cause this behaviour ?

--------------------- [font="Franklin Gothic Medium"]LinuxLive USB Creator[/font], [size="3"]The only Linux Live USB creator with easy integrated virtualization (made with AutoIT)[/size] ---------------------

Link to comment
Share on other sites

Latencies are still bullsh** though.

It could be your connection? This is something you would have to test yourself, perhaps speed-test.net? Also glad you solved the problem.

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

Link to comment
Share on other sites

Latencies are actually very low comparing to the real ones. My internet line is crappy and I have a few hundreds of msec of real latency. This piece of code is reporting milliseconds latencies.

It's like TCPConnect does not even wait for the socket to be really opened by the remote server.

--------------------- [font="Franklin Gothic Medium"]LinuxLive USB Creator[/font], [size="3"]The only Linux Live USB creator with easy integrated virtualization (made with AutoIT)[/size] ---------------------

Link to comment
Share on other sites

From Prompt:

Pinging 209.85.229.104 with 32 bytes of data:

Reply from 209.85.229.104: bytes=32 time=282ms TTL=46

Reply from 209.85.229.104: bytes=32 time=284ms TTL=45

Reply from 209.85.229.104: bytes=32 time=275ms TTL=46

Reply from 209.85.229.104: bytes=32 time=281ms TTL=46

From your program:

TCPConnect socket=444 - @error=0

209.85.229.104 is UP on port 80 - latency : 273.05ms

TCPConnect socket=424 - @error=0

209.85.229.104 is UP on port 80 - latency : 275.238ms

TCPConnect socket=416 - @error=0

209.85.229.104 is UP on port 80 - latency : 268.748ms

TCPConnect socket=412 - @error=0

209.85.229.104 is UP on port 80 - latency : 278.486ms

TCPConnect socket=432 - @error=0

209.85.229.104 is UP on port 80 - latency : 284.74ms

TCPConnect socket=444 - @error=0

209.85.229.104 is UP on port 80 - latency : 284.711ms

TCPConnect socket=424 - @error=0

209.85.229.104 is UP on port 80 - latency : 275.183ms

TCPConnect socket=416 - @error=0

209.85.229.104 is UP on port 80 - latency : 301.265ms

TCPConnect socket=412 - @error=0

209.85.229.104 is UP on port 80 - latency : 272.483ms

TCPConnect socket=432 - @error=0

209.85.229.104 is UP on port 80 - latency : 274.119ms

TCPConnect socket=444 - @error=0

209.85.229.104 is UP on port 80 - latency : 271.295ms

It seems pretty reliable for me.

Edited by TheGeneral
Link to comment
Share on other sites

I tried from home on the same PC and it's working as expected.

So it looks like if you have a transparent proxy this will not work (it will display latencies between your PC and the proxy and will never fail).

This is a bad news because this tool is intended for "professional use" and I need it to be reliable.

--------------------- [font="Franklin Gothic Medium"]LinuxLive USB Creator[/font], [size="3"]The only Linux Live USB creator with easy integrated virtualization (made with AutoIT)[/size] ---------------------

Link to comment
Share on other sites

Googling "TCP port ping" I got that:

http://code.google.com/p/paping/

I analyzed the TCP packets sent and they are SYN Flags. I don't know how to send this flags with TCPSend.

So, you have two options: use this program or finding a way to simulate its behavior with AutoIt.

I compared with TCPConnect and the behavior is the same. Check that:

Paping:

1 0.000000 192.168.1.33 200.147.67.142 TCP 66 58007 > http [SYN] Seq=0 Win=8192 Len=0 MSS=1460 WS=4 SACK_PERM=1
2 0.038109 200.147.67.142 192.168.1.33 TCP 66 http > 58007 [SYN, ACK] Seq=0 Ack=1 Win=5840 Len=0 MSS=1452 SACK_PERM=1 WS=128
3 0.038182 192.168.1.33 200.147.67.142 TCP 54 58007 > http [ACK] Seq=1 Ack=1 Win=66792 Len=0
4 0.038322 192.168.1.33 200.147.67.142 TCP 54 58007 > http [FIN, ACK] Seq=1 Ack=1 Win=66792 Len=0
5 0.076151 200.147.67.142 192.168.1.33 TCP 60 http > 58007 [FIN, ACK] Seq=1 Ack=2 Win=5888 Len=0
6 0.076207 192.168.1.33 200.147.67.142 TCP 54 58007 > http [ACK] Seq=2 Ack=2 Win=66792 Len=0

TCPConnect:

1 0.000000 192.168.1.33 209.85.229.104 TCP 66 58018 > http [SYN] Seq=0 Win=8192 Len=0 MSS=1460 WS=4 SACK_PERM=1
2 0.275632 209.85.229.104 192.168.1.33 TCP 66 http > 58018 [SYN, ACK] Seq=0 Ack=1 Win=14300 Len=0 MSS=1430 SACK_PERM=1 WS=64
3 0.275702 192.168.1.33 209.85.229.104 TCP 54 58018 > http [ACK] Seq=1 Ack=1 Win=65780 Len=0

TCPCloseSocket:

1 0.719827 192.168.1.33 209.85.229.104 TCP 54 58021 > http [FIN, ACK] Seq=1 Ack=1 Win=65780 Len=0
2 0.986404 209.85.229.104 192.168.1.33 TCP 60 http > 58021 [FIN, ACK] Seq=1 Ack=2 Win=14336 Len=0
3 0.986451 192.168.1.33 209.85.229.104 TCP 54 58021 > http [ACK] Seq=2 Ack=2 Win=65780 Len=0

What Paping does is the same you do. I just have a question, does Paping work with a transparent proxy?

Edited by TheGeneral
Link to comment
Share on other sites

  • 1 month 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...