Jump to content

faster smaller WAN IP receiver.


GtaSpider
 Share

Recommended Posts

Hi

Ive written a faster and smaller WAN IP receiver. This function may should be overwritten with the original "_GetIP",

because it dont need any tempfile and not _InetGetSource. Only pure autoit (TCP/IP)

Function with Example:

MsgBox(0,"",_ShortGetIP())


;===============================================================================
;
; Function Name:   _ShortGetIP
; Description::    Get WAN IP address of your Router
; Parameter(s):    -
; Requirement(s):  -
; Return Value(s): Return the WAN-IP address
; Author(s):       GtaSpider
;
;===============================================================================
;

Func _ShortGetIP()
    Local $iCon
    TCPStartup() ;If it doesnt done before
    $iCon = TCPConnect(TCPNameToIP("http://www.shrum.net"), 80)
    If @error Then Return SetError(1,0,0)
    TCPSend($iCon, "GET /getip.php HTTP/1.1" & @CRLF & "Host: www.shrum.net" & @CRLF & @CRLF)
    If @error Then Return SetError(2,0,0)
    Do
        $sRecv = TCPRecv($iCon, 1024)
        If @error Then Return SetError(3,0,0)
    Until StringLen($sRecv)
    Return StringTrimLeft($sRecv,StringInStr($sRecv,@CRLF&@CRLF)+3)
EndFunc   ;==>_ShortGetIP

I hope u like it :)

Your Spider

www.AutoIt.de - Moderator of the German AutoIt Forum

 

Link to comment
Share on other sites

Hi

Noone interessted? Here a speed comparison:

On my pc my function is > 2x faster and it dont make a tmpfile :)

#include <inet.au3>


Global Const $iCheck = 10 ; the more the merrier
Global $1,$2,$i
ProgressOn("","Analysing...")
While $i < $iCheck
    ProgressSet($i*100/$iCheck,Round($i*100/$iCheck)&"%")
    $i += 1
    $ti = TimerInit()
    $IP1 = _ShortGetIP()
    $1 += TimerDiff($ti)
    $ti = TimerInit()
    $IP2 = _GetIP()
    $2 += TimerDiff($ti)
WEnd
ProgressOff()
MsgBox(524288,"","_ShortGetIP() needs "&Round($1/$iCheck,2)&" ms and Return: "&$IP1&@CRLF&"_GetIP() needs "&Round($2/$iCheck,2)&" ms and Return: "&$IP2)

Func _ShortGetIP()
    Local $iCon
    TCPStartup() ;If it doesnt done before
    $iCon = TCPConnect(TCPNameToIP("http://www.shrum.net"), 80)
    If @error Then Return SetError(1, 0, 0)
    TCPSend($iCon, "GET /getip.php HTTP/1.1" & @CRLF & "Host: www.shrum.net" & @CRLF & @CRLF)
    If @error Then Return SetError(2, 0, 0)
    Do
        $sRecv = TCPRecv($iCon, 1024)
        If @error Then Return SetError(3, 0, 0)
    Until StringLen($sRecv)
    Return StringTrimLeft($sRecv, StringInStr($sRecv, @CRLF & @CRLF) + 3)
EndFunc   ;==>_ShortGetIP

Your Spider

Edited by GtaSpider

www.AutoIt.de - Moderator of the German AutoIt Forum

 

Link to comment
Share on other sites

Hi

It dont do anything more, than download the sourcecode of this site: http://www.shrum.net/getip.php :(

I havnt take www.whatsmyip.com or smth like this, because there are too many text.

But if u dont trust me ( :) ) then here is a other script for you, its the same, which uses the original _GetIP(), but now its much slower:

Func _ShortGetIP()
    Local $iCon
    TCPStartup() ;If it doesnt done before
    $iCon = TCPConnect(TCPNameToIP("checkip.dyndns.org"), 80)
    If @error Then Return SetError(1, 0, 0)
    TCPSend($iCon, "GET /index.php HTTP/1.1" & @CRLF & "Host: http://checkip.dyndns.org" & @CRLF & @CRLF)
    If @error Then Return SetError(2, 0, 0)
    Do
        $sRecv = TCPRecv($iCon, 1024)
        If @error Then Return SetError(3, 0, 0)
    Until StringLen($sRecv)
    Return StringTrimRight(StringTrimLeft($sRecv, StringInStr($sRecv, @CRLF & @CRLF) + 79),16)
EndFunc   ;==>_ShortGetIP

Your Spider

Edited by GtaSpider

www.AutoIt.de - Moderator of the German AutoIt Forum

 

Link to comment
Share on other sites

YOu could change the domain to http://www.whatismyip.org/ then.

Link to comment
Share on other sites

Hi

No, that wouldn't work, because u can only can receive your ip 5 times on 60 seconds.

But if u need it oftener (impossible is nothing :) ) it wont work.

Then this error Message comes: Error: 5 requests received from your IP address in the last 60 seconds (current max is 3 but automated agents should not query more often than once every 10 minutes)

Your Spider

www.AutoIt.de - Moderator of the German AutoIt Forum

 

Link to comment
Share on other sites

you have to Call TCPShutDown, too. For EVERY successful TCPStartup, you have to call TCPShutdown. And the _GetIP is fast, too, if you convert it to _InetGetSource:

#include <inet.au3>

_GetIP2()
Global Const $iCheck = 10 ; the more the merrier
Global $1,$2,$i
ProgressOn("","Analysing...")
While $i < $iCheck
    ProgressSet($i*100/$iCheck,Round($i*100/$iCheck)&"%")
    $i += 1
    $ti = TimerInit()
    $IP1 = _ShortGetIP()
    $1 += TimerDiff($ti)
    $ti = TimerInit()
    $IP2 = _GetIP2()
    $2 += TimerDiff($ti)
WEnd
ProgressOff()
MsgBox(524288,"","_ShortGetIP() needs "&Round($1/$iCheck,2)&" ms and Return: "&$IP1&@CRLF&"_GetIP2() needs "&Round($2/$iCheck,2)&" ms and Return: "&$IP2)

Func _ShortGetIP()
    Local $iCon
    TCPStartup() ;If it doesnt done before
    $iCon = TCPConnect(TCPNameToIP("checkip.dyndns.org"), 80)
    If @error Then Return SetError(1, 0, 0)
    TCPSend($iCon, "GET /index.php?rnd1="&Random(1,1234,1)&" HTTP/1.1" & @CRLF & "Host: http://checkip.dyndns.org" & @CRLF & @CRLF)
    If @error Then Return SetError(2, 0, 0)
    Do
        $sRecv = TCPRecv($iCon, 1024)
        If @error Then Return SetError(3, 0, 0)
    Until StringLen($sRecv)
    TCPShutdown() 
    Return StringTrimRight(StringTrimLeft($sRecv, StringInStr($sRecv, @CRLF & @CRLF) + 79),16)
EndFunc   ;==>_ShortGetIP

;===============================================================================
;
; Function Name:    _GetIP()
; Description:      Get public IP address of a network/computer.
; Parameter(s):     None
; Requirement(s):   Internet access.
; Return Value(s):  On Success - Returns the public IP Address
;                   On Failure - -1  and sets @ERROR = 1
; Author(s):        Larry/Ezzetabi & Jarvis Stubblefield, Convreted to _InetGetSource by Prog@ndy
;
;===============================================================================
Func _GetIP2()
    Local $ip, $t_ip, $txt
    $txt = _INetGetSource("http://checkip.dyndns.org/?rnd1=" & Random(1, 65536) & "&rnd2=" & Random(1, 65536))
    If  Not @error Then
        $ip = StringTrimLeft($txt, StringInStr($txt, ":") + 1)
        $ip = StringTrimRight($ip, StringLen($ip) - StringInStr($ip, "/") + 2)
        $t_ip = StringSplit($ip, '.')
        If $t_ip[0] = 4 And StringIsDigit($t_ip[1]) And StringIsDigit($t_ip[2]) And StringIsDigit($t_ip[3]) And StringIsDigit($t_ip[4]) Then
            Return $ip
        EndIf
    EndIf
    $txt = _INetGetSource("http://www.whatismyip.com/?rnd1=" & Random(1, 65536) & "&rnd2=" & Random(1, 65536))
    If Not @error Then
        $ip = StringTrimLeft($txt, StringInStr($txt, "Your ip is") + 10)
        $ip = StringLeft($ip, StringInStr($ip, " ") - 1)
        $ip = StringStripWS($ip, 8)
        $t_ip = StringSplit($ip, '.')
        If $t_ip[0] = 4 And StringIsDigit($t_ip[1]) And StringIsDigit($t_ip[2]) And StringIsDigit($t_ip[3]) And StringIsDigit($t_ip[4]) Then
            Return $ip
        EndIf
    EndIf
    SetError(1)
    Return -1
EndFunc   ;==>_GetIP2

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

Hi

you have to Call TCPShutDown, too.

Nope. If already a TCPStartup done, then the TCPStartup will be ignoriered.

But if you make TCPShutdown, then script who needs TCP (Chats or smth like this) wont work anymore..

And the _GetIP is fast, too, if you convert it to _InetGetSource:

Yes, thats rigth, but my function is 20 ms faster :)

And: It dont need any other Functions/Dll's. Its pure autoit.

I dont know why all of u hate my function... I createt this function for my own and i like it, so i thougth, maybe im not the only one who could like it.

But it looks like :(

However..

Your Spider

www.AutoIt.de - Moderator of the German AutoIt Forum

 

Link to comment
Share on other sites

I don't hate it. I just wanted to know, if winet.dll is faster :)

And you have to call TCPShutdown:

Remarks

There must be a TCPShutdown() call to avoid memory consomption.

A script must call one TCPShutdown() call for every successful TCPStartup() call.

UDPStartup() is just an alias of TCPStartup().

$1 = TCPStartup ( )
$2 = TCPStartup ( )
MsgBox(0, 'TCPStartUP',"It Returns: " & @CRLF &  $1 & " And No.2 (!!!): " & $2)
TCPShutdown()
TCPShutdown()
Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

Hi

Well, thats in the helpfile. But try this:

MsgBox(0,"","Now Check Memory..")
For $i = 1 To 100
$tcp = TCPStartup ( ) 
ConsoleWrite(@error & @CRLF)
ConsoleWrite($tcp & @CRLF)
Next
MsgBox(0,"","Now Check Memory.. Much more?")

Im not sure, but i think TcPShutdown is like Exit on end of your script. It looks better and clearer, but its not important :)

Your Spider

www.AutoIt.de - Moderator of the German AutoIt Forum

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...