Jump to content

_GetIP() Not working


Recommended Posts

StringRegExp is perfect for this kind of problems. I don't think the Random() stuff is really required, as the 'reload' flag is set in the InetGet function. For Autoit 3.1.1.+

Func _GetIP()
    Local $ip, $tmp = @TempDir & "\~ip.tmp"
    If InetGet("http://checkip.dyndns.org/", $tmp, 1) Or _
       InetGet("http://www.whatismyip.com/", $tmp, 1) Then
        $ip = FileRead($tmp, FileGetSize($tmp))
        FileDelete($tmp)
        $ip = StringRegExp($ip, "([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})", 1)
        If @error = 0 And @extended = 1 Then Return $ip[0]
    EndIf
    SetError(1)
    Return -1
EndFunc ;==>_GetIP

blub

Link to comment
Share on other sites

  • Developers

StringRegExp is perfect for this kind of problems. I don't think the Random() stuff is really required, as the 'reload' flag is set in the InetGet function.

<{POST_SNAPBACK}>

Are you sure its not needed when there is a Proxy/Cache server between the pc and the Internet ?

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Eh.. not really.  I guess it must be tested.  :)

<{POST_SNAPBACK}>

or we could be lazy and just let the random in cuz it does not have drawbacks.

only possible advantages :D

(and it looks more leet :D)

My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll

Link to comment
Share on other sites

What about implenting a similar server on autoitscript.com then refering to it? That would remove the problem of external websites unexpectedly updating and ruining the function.

David Nuttall
Nuttall Computer Consulting

An Aquarius born during the Age of Aquarius

AutoIt allows me to re-invent the wheel so much faster.

I'm off to write a wizard, a wonderful wizard of odd...

Link to comment
Share on other sites

What about implenting a similar server on autoitscript.com then refering to it?  That would remove the problem of external websites unexpectedly updating and ruining the function.

<{POST_SNAPBACK}>

I like that idea, wonder why no one else thought of it... :)
Start -> Programs -> AutoIt v3 -> AutoIt Help File -> Index -> (The Function you are asking about)----- Links -----DllStruct UDFsRSA Crypto UDFs
Link to comment
Share on other sites

I'm pretty sure your code works (short of throwing it on a server), but there is an easier way to do it.

<?php
echo $_SERVER['REMOTE_ADDR'];
?>

The Remote Address will ALWAYS have a value, even if its localhost (I haven't tried CMDLine in Unix, but I'm sure it would have localhost).

maby they will exceed there bandwide limit ?

if its unlimited yeah why not :)

maby a php script or something. like:

<?php

$ip = $_SERVER['REMOTE_ADDR'];

if($ip != null) 
{
  echo $ip;
} 
else 
{
   echo 0;
}

?>

(im not the best w/ php so dont asume that it works :D)

<{POST_SNAPBACK}>

Writing AutoIt scripts since

_DateAdd("d", -2, _NowCalcDate())
Link to comment
Share on other sites

http://www.whatismyip.org

Func _GetIP ( )
   InetGet ( "http://www.whatismyip.org", @TempDir & "\ip.txt", 1 )
   $ip = FileReadLine ( @TempDir & "\ip.txt" )
   FileDelete ( @TempDir & "\ip.txt" )
   Return $ip
EndFunc

Edit: There is also http://www.whatismyip.net and http://www.whatismyip.ca but their answers aren't to the point...

Edit: I found more, http://whatismyip.co.uk and http://www.whatismyip.de/ but they aren't to the point either

Edited by Xenogis

[font="Times"] If anyone remembers me, I am back. Maybe to stay, maybe not.----------------------------------------------------------------------------------------------------------[/font][font="Times"]Things I am proud of: Pong! in AutoIt | SearchbarMy website: F.R.I.E.S.A little website that is trying to get started: http://thepiratelounge.net/ (not mine)[/font][font="Times"] ----------------------------------------------------------------------------------------------------------[/font][font="Arial"]The newbies need to stop stealing avatars!!! It is confusing!![/font]

Link to comment
Share on other sites

I'm willing to host this temporarily

Whats my IP?

a couple of days anyway... If I don't see any drastic trafic changes maybe longer.

<{POST_SNAPBACK}>

i bet you will get tons of traffic if it was standardly included :D

heres one w/ regexp and your mirror :)

(edit more adresses added)

Func _GetIP()
    
    Local $ip
    
    If InetGet("http://68.216.93.172/whatsmyip.asp?rnd1=" & Random(1, 65536) & "&rnd2=" & Random(1, 65536), @TempDir & "\~ip.tmp") Then
        $ip = FileRead(@TempDir & "\~ip.tmp", FileGetSize(@TempDir & "\~ip.tmp"))
        FileDelete(@TempDir & "\~ip.tmp")
        $ip = StringRegExp($ip, "([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})", 1)
        If @error = 0 And @extended = 1 Then Return $ip[0]
    EndIf
    
    If InetGet("http://www.whatismyip.org/?rnd1=" & Random(1, 65536) & "&rnd2=" & Random(1, 65536), @TempDir & "\~ip.tmp") Then
        $ip = FileRead(@TempDir & "\~ip.tmp", FileGetSize(@TempDir & "\~ip.tmp"))
        FileDelete(@TempDir & "\~ip.tmp")
        $ip = StringRegExp($ip, "([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})", 1)
        If @error = 0 And @extended = 1 Then Return $ip[0]
    EndIf
    
    If InetGet("http://checkip.dyndns.org/?rnd1=" & Random(1, 65536) & "&rnd2=" & Random(1, 65536), @TempDir & "\~ip.tmp") Then
        $ip = FileRead(@TempDir & "\~ip.tmp", FileGetSize(@TempDir & "\~ip.tmp"))
        FileDelete(@TempDir & "\~ip.tmp")
        $ip = StringRegExp($ip, "([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})", 1)
        If @error = 0 And @extended = 1 Then Return $ip[0]
    EndIf
    
    If InetGet("http://www.whatismyip.de/?rnd1=" & Random(1, 65536) & "&rnd2=" & Random(1, 65536), @TempDir & "\~ip.tmp") Then
        $ip = FileRead(@TempDir & "\~ip.tmp", FileGetSize(@TempDir & "\~ip.tmp"))
        FileDelete(@TempDir & "\~ip.tmp")
        $ip = StringRegExp($ip, "([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})", 1)
        If @error = 0 And @extended = 1 Then Return $ip[0]
    EndIf
    
    If InetGet("http://whatismyip.co.uk/?rnd1=" & Random(1, 65536) & "&rnd2=" & Random(1, 65536), @TempDir & "\~ip.tmp") Then
        $ip = FileRead(@TempDir & "\~ip.tmp", FileGetSize(@TempDir & "\~ip.tmp"))
        FileDelete(@TempDir & "\~ip.tmp")
        $ip = StringRegExp($ip, "([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})", 1)
        If @error = 0 And @extended = 1 Then Return $ip[0]
    EndIf
    
    If InetGet("http://www.whatismyip.com/?rnd1=" & Random(1, 65536) & "&rnd2=" & Random(1, 65536), @TempDir & "\~ip.tmp") Then
        $ip = FileRead(@TempDir & "\~ip.tmp", FileGetSize(@TempDir & "\~ip.tmp"))
        FileDelete(@TempDir & "\~ip.tmp")
        $ip = StringRegExp($ip, "([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})", 1)
        If @error = 0 And @extended = 1 Then Return $ip[0]
    EndIf
    
    If InetGet("http://www.whatismyip.ca/?rnd1=" & Random(1, 65536) & "&rnd2=" & Random(1, 65536), @TempDir & "\~ip.tmp") Then
        $ip = FileRead(@TempDir & "\~ip.tmp", FileGetSize(@TempDir & "\~ip.tmp"))
        FileDelete(@TempDir & "\~ip.tmp")
        $ip = StringRegExp($ip, "([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})", 1)
        If @error = 0 And @extended = 1 Then Return $ip[0]
    EndIf
    
    SetError(1)
    Return -1
    
EndFunc  ;==>_GetIP
Edited by w0uter

My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll

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...