Kyan

Alternative to ICMP

8 posts in this topic

Hi

My antivirus blocks ping requests when I'm not in a trusted zone, and I can't disable it (Pretty stupid eset folks), there's any other alternative to check if a website is online?

 

Thanks in advance


Heroes, there is no such thing

One day I'll discover what IE.au3 has of special for so many users using it.
C'mon there's InetRead and WinHTTP, way better
happy.png

Share this post


Link to post
Share on other sites




If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

there're any other website that works with http headers (faster that way)

found this

CbI623m.png

Don't know if is possible to make something like this using autoit code


Heroes, there is no such thing

One day I'll discover what IE.au3 has of special for so many users using it.
C'mon there's InetRead and WinHTTP, way better
happy.png

Share this post


Link to post
Share on other sites

Just a curiosity, how long does it take to use the two methods in comparison to each other? Also, how short of a time span are you attempting to reach if you're only checking to see if a site is up or not? I can't imagine that either method is going to severely impact the script if you're checking for something like that. After all a ping takes time to complete too.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Microsoft has a tcp ping tool too https://technet.microsoft.com/en-us/sysinternals/jj729731.aspx

this uses icmp https://msdn.microsoft.com/en-us/library/hb7xxkfx%28v=vs.110%29.aspx

@Brew my worst enemy is timeouts, functions usually don't have them :s

EDIT:

#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

Posting the request times soon (man gotta eat,you know :D)

Edited by Kyan

Heroes, there is no such thing

One day I'll discover what IE.au3 has of special for so many users using it.
C'mon there's InetRead and WinHTTP, way better
happy.png

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

@BrewManNH

Opt("TCPTimeout",200) ;200ms timeout
TCPStartup()
$inet = TimerInit()
$page = BinaryToString(InetRead("http://downforeveryoneorjustme.com/autoitscript.com",1),4)
If StringRegExp($page,'(?i)class="domain">.+?</span> is up') Then ConsoleWrite("INET: "&TimerDiff($inet)&@LF)
$ping = TimerInit()
_PingPort(TCPNameToIP("autoitscript.com"), 80)
ConsoleWrite("TCPing: "&TimerDiff($ping)&@LF)
TCPShutdown()
Exit

#cs ----------------------------------------------------------------------------
 Author:         cppman
 Script Function: _PingPort
#ce ----------------------------------------------------------------------------
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

Output

INET: 1637,50964253886
TCPing: 247,94185862592

I think 1390ms of difference is something :)

EDIT2: Test2

Opt("TCPTimeout",200) ;200ms timeout
TCPStartup()
$inet = TimerInit()
$page = BinaryToString(InetRead("http://downforeveryoneorjustme.com/autoitscript.com",1),4)
If StringRegExp($page,'(?i)class="domain">.+?</span> is up') Then ConsoleWrite("INET: "&TimerDiff($inet)&@LF)
$ping = TimerInit()
_PingPort(TCPNameToIP("autoitscript.com"), 80)
ConsoleWrite("_PingPort: "&TimerDiff($ping)&@LF)
$tcping = TimerInit()
TCPing(TCPNameToIP("autoitscript.com"))
ConsoleWrite("TCPing: "&TimerDiff($tcping)&@LF)
TCPShutdown()
Exit

#cs ----------------------------
 Author:         cppman
 Script Function: _PingPort
#ce ----------------------------
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

#cs ----------------------------
 Author:             kyan
 Script Function:    TCPing
 
 Remarks: Use TCPNameToIP() to obtain a computer/website IP
          You must run TCPStartup() before using this function
#ce ----------------------------
Func TCPing($_ip, $_port = 80)
    $timer = TimerInit()
    $sock = TCPConnect($_ip, $_port)
    If @error Then SetError(@error,0,-1)
    ;@€rror
    ;   1 Invalid IP
    ;   2 Invalid Port
    ;
    $_reqtime = TimerDiff($timer)
    TCPCloseSocket($sock)
    Return $_reqtime
EndFunc
INET: 884.828031365957
_PingPort: 74.2614979757707
TCPing: 62.199046572375

TCPing function :)

#cs ----------------------------
 Author:             kyan
 Script Function:    TCPing
 Release date:       22/04/2015 2:44AM
 Vwrsion:            1.0
 
 Variables:
        $Server: IPv4 or server name, ex: 192.168.1.1 or example.com
        (Optional) $ServerPort: Server's port you want to ping
        
 @error:
        1 Invalid IP
        2 Invalid Port
        3 Failed to retrieve server/computer IP
    
 Remarks: You must run TCPStartup() before using this function
#ce ----------------------------
Func TCPing($server, $ServerPort = 80)
    If Not StringRegExp($server,"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}") Then $server = TCPNameToIP($server)
    If @error Then SetError(3)
    $timer = TimerInit()
    $sock = TCPConnect($server, $ServerPort)
    If @error Then SetError(@error,0,-1)
    $_reqtime = TimerDiff($timer)
    TCPCloseSocket($sock)
    Return $_reqtime
EndFunc
Edited by Kyan

Heroes, there is no such thing

One day I'll discover what IE.au3 has of special for so many users using it.
C'mon there's InetRead and WinHTTP, way better
happy.png

Share this post


Link to post
Share on other sites

Like I said, even 1.4 seconds isn't a long time to wait if you're not doing anything else with the script at the time. The time difference would only be a problem if 1.4 seconds makes any difference at all to your running script. Seeing as how I have no idea why you need to find out if a site is up or not it's impossible for me to know if that would make any kind of difference to your script.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

I made a script that extracts those hosters links, usually takes 200-400ms to do it in one link, but since I changed some firewall rules on my eset I can't revert back ICMP blocking in non trusted zones, so I needed an alternative to icmp :)

EDIT: TCPNameToIP has timeout issues and noanasd.com (made up name)

Opt("TCPTimeout",200) ;200ms timeout
TCPStartup()
ConsoleWrite(TCPing("noanasd.com")&@LF)
TCPShutdown()
Exit

returns 0.0798532747264897  :think:

Edited by Kyan

Heroes, there is no such thing

One day I'll discover what IE.au3 has of special for so many users using it.
C'mon there's InetRead and WinHTTP, way better
happy.png

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