Jump to content
Sign in to follow this  
NELyon

Retrieve External IP

Recommended Posts

It's official. I'm back using Autoit! After a... 6 Month leave from programming. I stuck around the forums anyway :P

So anyway, this retrieves your external IP address using cleaner (and less) code then _GetIP()

It also has a param, $file, in which you can save your IP to an external file instead of the function returning it.

It is my first working script in over 6 months, so be gentle! Remember, I may be reinventing the wheel, but my wheel, IMO, gets better traction on those bumpy roads :)

Func _RetrieveIP($file = "")
    local $ip, $tempfile = @TempDir & "\ip.txt"
    If $file = "" Then
        InetGet("http://whatismyip.com/automation/n09230945.asp",  $tempfile)
        If @Error Then
            return 0
        Else 
            $ip = FileRead($tempfile)
            return $ip
        EndIf
    ElseIf $file <> "" Then
        InetGet("http://whatismyip.com/automation/n09230945.asp",  $tempfile)
    If @error Then
            return 0
        Else
            FileMove($tempfile, $file)
        EndIf
    EndIf
    FileDelete($tempfile)
EndFuncoÝ÷ ØX¥xLZ^jëh×6_RetrieveIP("C:\MyIP.txt")

Func _RetrieveIP($file = "")

local $ip, $tempfile = @TempDir & "\ip.txt"

If $file = "" Then

InetGet("http://whatismyip.com/automation/n09230945.asp", $tempfile)

If @Error Then

return 0

Else

$ip = FileRead($tempfile)

return $ip

EndIf

ElseIf $file <> "" Then

InetGet("http://whatismyip.com/automation/n09230945.asp", $tempfile)

If @error Then

return 0

Else

FileMove($tempfile, $file)

EndIf

FileDelete($tempfile)

EndFunc

Welcome back Autoit!

Edited by Senton-Bomb

Share this post


Link to post
Share on other sites

Welcome back!

I think this is shorter: http://www.whatismyip.org/


[u]My Projects[/u]:General:WinShell (Version 1.6)YouTube Video Downloader Core (Version 2.0)Periodic Table Of Chemical Elements (Version 1.0)Web-Based:Directory Listing Script Written In AutoIt3 (Version 1.9 RC1)UDFs:UnicodeURL UDFHTML Entity UDF[u]My Website:[/u]http://dhilip89.hopto.org/[u]Closed Sources:[/u]YouTube Video Downloader (Version 1.3)[quote]If 1 + 1 = 10, then 1 + 1 ≠ 2[/quote]

Share this post


Link to post
Share on other sites

OMG somebody save me from the Autoit Tags.

I can't edit my post. That random code sitting at the bottom of my post won't go away, and if i try to remove it, my code gets screwed.

EDIT:

Forgot to mention: This was developed in Linux with Wine, so it's 100% Wine Compatible :)

@Dhillip

This is to return your IP dynamically for use in code, such as for testing a web server.

Edited by Senton-Bomb

Share this post


Link to post
Share on other sites

Hi!

You want short code?

Try this:

$ip=StringMid(InetGet("http://alexissoft.free.fr/ip.php",  "ip_temp.txt")&FileRead("ip_temp.txt"),2)

:)

Edited by Michel Claveau

Share this post


Link to post
Share on other sites

Also look _GetIP in the help file

The whole point of this code was to retrieve the IP in less code than that very function :)

Thanks anyway!

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...