Sign in to follow this  
Followers 0
Ejoc

_GetIP() Not working

31 posts in this topic

#1 ·  Posted (edited)

It's returning "" for me...

It's getting the file correctly, just seems like myipaddress must have changed it's HTML code slightly. I got it working but I'm using a more hard-code version, it's probably an easy fix.

*EDIT

Ok, I looked into it, and since it's needs to be worked on, I fixed-up the new_GetIP():

;===============================================================================
;
; Function Name:        new_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
; Proxy Revision by:    warmfuzzy
; Original Author(s):   Larry/Ezzetabi & Jarvis Stubblefield 
; Comments:          Reduces likelihood of Proxy Caching problems
;===============================================================================

; Demo bit
local $PublicIP = new_GetIP()
MsgBox(0, "IP Address", "Your IP Address is: " & $PublicIP)
Exit

; Function replacing _GetIP() in Include\Inet.au3 via #include <Inet.au3>
Func new_GetIP()
    Local $ip
    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 = StringTrimLeft($ip, StringInStr($ip, "<TITLE>Your ip is") + 17)
        $ip = StringLeft($ip, StringInStr($ip, "WhatIsMyIP.com</TITLE>") - 1)
        $ip = StringStripWS($ip,8)
        Return $ip
    Else
        SetError(1)
        Return -1
    EndIf
EndFunc;Function End >> new_GetIP()
Edited by Ejoc

Start -> Programs -> AutoIt v3 -> AutoIt Help File -> Index -> (The Function you are asking about)----- Links -----DllStruct UDFsRSA Crypto UDFs

Share this post


Link to post
Share on other sites



yes they changed the page..

here's a working version:

Func _GetIP()
    Local $ip
    If InetGet("http://www.whatismyip.com", @TempDir & "\~ip.tmp") Then
        $ip = FileRead(@TempDir & "\~ip.tmp", FileGetSize(@TempDir & "\~ip.tmp"))
        FileDelete(@TempDir & "\~ip.tmp")
        $ip = StringTrimLeft($ip, StringInStr($ip, "<TITLE>Your ip is") + 17)
        $ip = StringLeft($ip, StringInStr($ip, "WhatIsMyIP.com</TITLE>") - 1)
        Return StringReplace($ip, @TAB, '')
    Else
        SetError(1)
        Return -1
    EndIf
EndFunc  ;==>_GetIP

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Define better :D

I just fixed the one submitted to me a while ago which is in the current installer....

No issue with replacing it with a "Better" version.....


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

:) ... will update the _getip() UDF as proposed..... tnx

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

They Changed it again...


Start -> Programs -> AutoIt v3 -> AutoIt Help File -> Index -> (The Function you are asking about)----- Links -----DllStruct UDFsRSA Crypto UDFs

Share this post


Link to post
Share on other sites

A function which relies on an external site like this probably should not be a standard function in the official distribution. If it can't be done 1st-party, it shouldn't be included so that issues like this are prevented.

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

They Changed it again...

<{POST_SNAPBACK}>

Updated version, made it less sensitive for updates:

Func _GetIP()
    Local $ip
    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 = StringTrimLeft($ip, StringInStr($ip, "Your ip is") + 10)
        $ip = StringLeft($ip, StringInStr($ip, " ") - 1)
        $ip = StringStripWS($ip, 8)
        Return $ip
    Else
        SetError(1)
        Return -1
    EndIf
EndFunc;==>_GetIP

A function which relies on an external site like this probably should not be a standard function in the official distribution.  If it can't be done 1st-party, it shouldn't be included so that issues like this are prevented.

<{POST_SNAPBACK}>

We need to keep this in mind for future UDF's.... Edited by JdeB

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

http://checkip.dyndns.org/

Seems to have a more static and simpler output format...

<{POST_SNAPBACK}>

that one is alot better b/c it downloads faster

Func _GetIP()
    Local $ip
    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 = StringTrimLeft($ip, StringInStr($ip, ":") + 1)
        $ip = StringTrimRight($ip, StringLen($ip) - StringInStr($ip, "/") + 2)
        Return $ip
    Else
        SetError(1)
        Return -1
    EndIf
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

Share this post


Link to post
Share on other sites

http://checkip.dyndns.org/

Seems to have a more static and simpler output format...

<{POST_SNAPBACK}>

Nice call :)

FootbaG

Share this post


Link to post
Share on other sites

so what about this way?

Func _GetIP()
    Local $ip, $t_ip
    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 = StringTrimLeft($ip, StringInStr($ip, ":") + 1)
        $ip = StringTrimRight($ip, StringLen($ip) - StringInStr($ip, "/") + 2) & "x"
        ConsoleWrite('@@ Debug(26) : $ip = ' & $ip & @lf);### Debug Console
        $t_ip = StringSplit($ip,'.')
        If $t_ip[0] = 4 Then 
            Return $ip
        EndIf
    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 = StringTrimLeft($ip, StringInStr($ip, "Your ip is") + 10)
        $ip = StringLeft($ip, StringInStr($ip, " ") - 1)
        $ip = StringStripWS($ip, 8)
        If $t_ip[0] = 4 Then 
            Return $ip
        EndIf
    EndIf
    SetError(1)
    Return -1
EndFunc;==>_GetIP

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

@jdeb i think you forgot StringSplit at the whatsmyip.com part

and what is that X doing at the StringTrimRight ?

also you could use StringIsDigit to check if it actually is an ip

an not an ip with a <body> tag atached or something

this is what it is suppose to be acording to me (i could be wrong though)

Func _GetIP()
    Local $ip, $t_ip
    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 = StringTrimLeft($ip, StringInStr($ip, ":") + 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
    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 = StringTrimLeft($ip, StringInStr($ip, "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  ;==>_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

Share this post


Link to post
Share on other sites

@jdeb i think you forgot StringSplit at the whatsmyip.com part

and what is that X doing at the StringTrimRight ?

also you could use StringIsDigit to check if it actually is an ip

an not an ip with a <body> tag atached or something

this is what it is suppose to be acording to me (i could be wrong though)

<{POST_SNAPBACK}>

sounds good... tnx

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#19 ·  Posted (edited)

Why not have a page hosted by autoit return your IP and make _GetIP() access the autoit page? That way you know it wont change.

Edited by Ejoc

Start -> Programs -> AutoIt v3 -> AutoIt Help File -> Index -> (The Function you are asking about)----- Links -----DllStruct UDFsRSA Crypto UDFs

Share this post


Link to post
Share on other sites

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)


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

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  
Followers 0