Jump to content

Suggested Change


Recommended Posts

Here is the untouched... (Downloads a page containing your IP to @TempDir, and uses String functions to pull the IP from the HTML)

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   ;==>_GetIPoÝ÷ Ù³(v'âyÕ^®È¨öÍ 8¬§zËÙè²ÚâîËb¢{"~Ø^~*ìµDKv¬_j)Ly©â­®éì~º&騯,!Èl¥u·jË^­«­¢+ÙÕ¹}Ñ%@ ¤(1½°ÀÌØí¥À°ÀÌØíÑ}¥À(ÀÌØí¥Àô}%¹ÑÑM½ÕÉ ÅÕ½Ðí¡ÑÑÀè¼½ÝÝܹݡѥ͵å¥À¹½ÉÅÕ½Ðì¤(ÀÌØíÑ}¥ÀôMÑÉ¥¹MÁ±¥Ð ÀÌØí¥À°Ìäì¸Ìäì¤(%ÀÌØíÑ}¥ÁlÁtôйMÑÉ¥¹%Í¥¥Ð ÀÌØíÑ}¥ÁlÅt¤¹MÑÉ¥¹%Í¥¥Ð ÀÌØíÑ}¥ÁlÉt¤¹MÑÉ¥¹%Í¥¥Ð ÀÌØíÑ}¥ÁlÍt¤¹MÑÉ¥¹%Í¥¥Ð ÀÌØíÑ}¥ÁlÑt¤Q¡¸(IÑÕɸÀÌØí¥À(¹%(ÀÌØí¥Àô}%9ÑÑM½ÕÉ ÅÕ½Ðí¡ÑÑÀè¼½¡­¥À¹å¹¹Ì¹½É¼ýɹÄôÅÕ½ÐìµÀìI¹½´ Ä°ØÔÔÌؤµÀìÅÕ½ÐìµÀíɹÈôÅÕ½ÐìµÀìI¹½´ Ä°ØÔÔÌؤ¤(%ÀÌØí¥ÀQ¡¸(ÀÌØí¥ÀôMÑÉ¥¹QÉ¥µ1Ð ÀÌØí¥À°MÑÉ¥¹%¹MÑÈ ÀÌØí¥À°ÅÕ½ÐìèÅÕ½Ð줬Ĥ(ÀÌØí¥ÀôMÑÉ¥¹QÉ¥µI¥¡Ð ÀÌØí¥À°MÑÉ¥¹1¸ ÀÌØí¥À¤´MÑÉ¥¹%¹MÑÈ ÀÌØí¥À°ÅÕ½Ðì¼ÅÕ½Ð줬Ȥ(ÀÌØíÑ}¥ÀôMÑÉ¥¹MÁ±¥Ð ÀÌØí¥À°Ìäì¸Ìäì¤(%ÀÌØíÑ}¥ÁlÁtôйMÑÉ¥¹%Í¥¥Ð ÀÌØíÑ}¥ÁlÅt¤¹MÑÉ¥¹%Í¥¥Ð ÀÌØíÑ}¥ÁlÉt¤¹MÑÉ¥¹%Í¥¥Ð ÀÌØíÑ}¥ÁlÍt¤¹MÑÉ¥¹%Í¥¥Ð ÀÌØíÑ}¥ÁlÑt¤Q¡¸(IÑÕɸÀÌØí¥À(¹%(¹%(ÀÌØí¥Àô}%9ÑÑM½ÕÉ ÅÕ½Ðí¡ÑÑÀè¼½ÝÝܹݡѥ͵å¥À¹½´¼ýɹÄôÅÕ½ÐìµÀìI¹½´ Ä°ØÔÔÌؤµÀìÅÕ½ÐìµÀíɹÈôÅÕ½ÐìµÀìI¹½´ Ä°ØÔÔÌؤ¤(%ÀÌØí¥ÀQ¡¸(ÀÌØí¥ÀôMÑÉ¥¹QÉ¥µ1Ð ÀÌØí¥À°MÑÉ¥¹%¹MÑÈ ÀÌØí¥À°ÅÕ½Ðíe½ÕÈ¥À¥ÌÅÕ½Ð줬ÄÀ¤(ÀÌØí¥ÀôMÑÉ¥¹1Ð ÀÌØí¥À°MÑÉ¥¹%¹MÑÈ ÀÌØí¥À°ÅÕ½ÐìÅÕ½Ð줴Ĥ(ÀÌØí¥ÀôMÑÉ¥¹MÑÉ¥Á]L ÀÌØí¥À°à¤(ÀÌØíÑ}¥ÀôMÑÉ¥¹MÁ±¥Ð ÀÌØí¥À°Ìäì¸Ìäì¤(%ÀÌØíÑ}¥ÁlÁtôйMÑÉ¥¹%Í¥¥Ð ÀÌØíÑ}¥ÁlÅt¤¹MÑÉ¥¹%Í¥¥Ð ÀÌØíÑ}¥ÁlÉt¤¹MÑÉ¥¹%Í¥¥Ð ÀÌØíÑ}¥ÁlÍt¤¹MÑÉ¥¹%Í¥¥Ð ÀÌØíÑ}¥ÁlÑt¤Q¡¸(IÑÕɸÀÌØí¥À(¹%(¹%(MÑÉÉ½È Ä¤(IÑÕɸ´Ä)¹Õ¹ìôôÐí}Ñ%@

It just seems to me that this is a slightly more effective way to do this... I could be completely off my rocker, I usually am...

Wouldn't this be better? If not, why?

I'm just curious, and want to learn here... ;)

P.S. This is more of a conversation piece... ^_^

Edited by BinaryBrother

SIGNATURE_0X800007D NOT FOUND

Link to comment
Share on other sites

#include<inet.au3>

Func __GetIP()
   Local $aIP = StringRegExp(_InetGetSource("http://checkip.dyndns.org/"), "\d[\d\.]+", 1)
   If NOT @Error Then
      Return $aIP[0]
   EndIf
   Return 0
EndFunc

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Show off... ^_^

Actually I was referring internally to the "Inet.au3" UDF, so the include in your example wouldn't be needed, as the "_GetIP()" function is a part of that UDF.

But, your point was made as far as improvements is concerned... ;)

SIGNATURE_0X800007D NOT FOUND

Link to comment
Share on other sites

If you had checked it you wold have noticed that for testing I chaged the function name using 2 underscores.

Another 4 lines of code makes it work for the other site as well.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

lol George, I don't why but I feel it's not correct to match IP address this way. Try this funny way:

Dim $sPattern = '\b(?>(?:[01]?\d?\d|25[0-5]|2[0-4]\d)\.){3}(?:[01]?\d?\d|25[0-5]|2[0-4]\d)\b'
Dim $sIPs = '', $aIPs

For $i = 1 To 50
    $sIPs &= String(Random(0, 290, 1))
    
    For $j = 1 To 3
        $sIPs &= '.' & String(Random(0, 290, 1))
    Next
    $sIPs &= '|'
Next

$aIPs = StringSplit(StringTrimRight($sIPs, 1), '|')

For $i = 1 To $aIPs[0]
    If StringRegExp($aIPs[$i], $sPattern) Then
        ConsoleWrite('+' & $aIPs[$i] & @TAB & '  =)' & @LF)
    Else
        ConsoleWrite('!' & $aIPs[$i] & @TAB & '  =(' & @LF)
    EndIf
Next
Link to comment
Share on other sites

@Authenticity

^_^ I used your pattern for mine... Good deal... ;)

Just out of curiosity... Any of you guys know what the Developers are cooking up next? Are they doing Bug-fixes and optimizations for the current release, or working on another Beta with new features? :(

Edited by BinaryBrother

SIGNATURE_0X800007D NOT FOUND

Link to comment
Share on other sites

Read the Developers forum, there are a few more things in the list to do before the release but it's very closer seen =]. I think _GetIP is not the in hot things to do list but who knows. It's not practical to use external resource to get your IP address. Look here if you need example of how to get it. You're looking for GetIpAddrTable.

Edited by Authenticity
Link to comment
Share on other sites

I was digging for a way to get it locally without the need for an external resource due to the possibility of servers being down and such... I figured that wasn't practical, but couldn't find a better way, I'm already putting that C++ example to good use, Gotta go download all my tools again as I just done a fresh OS install... ^_^

SIGNATURE_0X800007D NOT FOUND

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