Jump to content

new_GetIP()


warmfuzzy
 Share

Recommended Posts

Suggestion: Adding pseudo-random numbers to IP address scrape to avoid problems where transparent proxy servers (e.g. Squid) may cache IP address request.

Attached: new_GetIP.au3

Edited to be less terse:

Most (A)DSL and Cablemodem users are browsing the web behind a transparent proxy, usually Squid, and don't realize it. This is typically done as ISPs oversell their bandwidth, so proxying allows static information to be only downloaded once. e.g. if 10 people request the front page of google, it only needs to be downloaded once. Dynamic information is usually not proxied, nor is information on ports other than 80 (http/web).

There is also an obscure but everpresent proxy bug that also causes stale information due to the automagic redirection of a web address without a slash at the end to a web address with a slash at the end, coupled with serving up the contents of the default web page, typically index.html. In other words, www.zombo.com will get you www.zombo.com/ which is actually serving up www.zombo.com/index.html

The obscure problem is that proxies don't always update the main requested page (i.e. if you request it without the slash) but do update the .../index.html page in the proxy cache, if you request it specifically.

All this to say, that the _GetIP() function in Inet.au3 does a web scrape using default port 80, to www.whatismyip.com without a slash. So it's particularly susceptible to the redirection plus the obscure proxy caching bug.

Which means that the answer you get back might or might not be still valid.

While proxy servers are supposed to honor non-caching headers and so forth, they don't always. If www.whatismyip.com responded on a different port, it wouldn't be cached. Since we can't avoid using port 80 in this case, this new_GetIP() suggested code appends pseudo-random numbers as parameters passed to www.whatismyip.com (which doesn't use them); The pseudo-random numbers greatly increase the chance that that particular request isn't in the proxy cache, and that the information you'll be served is more likely to be valid.

There. Less terse, more satisfying.

Edited by warmfuzzy
Link to comment
Share on other sites

  • 3 weeks later...

The title changed: it has now embedded tabs, CR/LF; so, the new_GetIP() should be changed to:

; 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()
I removed the trailing space in "<TITLE>Your ip is " and the leading one in " WhatIsMyIP.com</TITLE>", and finally addded a StringStripWS to remove all the tabs, CR/LF.

Gestion des congés, RTT, vacances scolaires, autres absences sur Pocket PC : CongésRFV

Link to comment
Share on other sites

The title changed

Looks like they keep changing it, to avoid web scrapers having an easy time of it.

Perhaps it's just time to "cut our losses" and not depend on a third party web address that will keep trying to obfuscate their output.

Ideally, we should use a different method, or at least an alternate source.

Of course, autoitscript.com could always provide an ip.cgi Perl script that would have consistent output. Then autoitscripts could get their IP address reliably from autoitscript.com. Otherwise every time www.whatismyip.com changes their title format, the _GetIP() script will break, breaking scripts out in the field.

That would make sense, autoit relying on autoit rather than a third party (even a benefactor may have issues over time).

ip.zip

Edited by warmfuzzy
Link to comment
Share on other sites

Or, we could use this more robust function that depends on the StringRegExp() function, which is available in v3.1.0.14 (beta) and 3.1.1++ (beta) only.

Func _GetIP()
    Local $ip, $tmp = @TempDir & "\~ip.tmp"
    Local $rnd = "/?rnd1=" & Random(1,65536) & "&rnd2=" & Random(1,65536)

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

blub

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