Jump to content

Retrieve External IP


NELyon
 Share

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

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

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

Thanks anyway!

That's what happens when i skim the thread...lol

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

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