JohnOne Posted September 27, 2014 Share Posted September 27, 2014 (edited) Get's your external IP address. Respects IP retrieval providers by randomizing which site is used. Safeguards AutoIt's "good name". EDIT2: fluffy & fast UDF includes 3 method shown to post #6 Bottom of post. Usage. #include "ExternalIP.au3" MsgBox(0,0,_ExtIP()) EDIT3: If it's speed you're after then I recommend >this UDF which uses STUN protocol and is lightning quick. #include <Array.au3> MsgBox(0,0,_ExtIP()) Func _ExtIP() Local $UA = HttpSetUserAgent("Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.124 Safari/537.36") Local $aSites2[3] = ["http://checkip.dyndns.org", "http://www.myexternalip.com/raw", "http://bot.whatismyipaddress.com"] _ArrayShuffle($aSites2) Local $step = 1 Local $Ramdom = Random(0, 1, 1) If $Ramdom Then $step = -1 EndIf For $i = $Ramdom To Not $Ramdom Step $step $sRead = BinaryToString(InetRead($aSites2[$i])) $aRXP = StringRegExp($sRead, "((?:\d{1,3}\.){3}\d{1,3})", 3) If Not @error And $aRXP[0] <> "" Then HttpSetUserAgent($UA) Return $aRXP[0] EndIf Next HttpSetUserAgent($UA) Return 0 EndFunc ;==>_ExtIP I acknowledge that only 2 websites are checked from the list, I just could not be bothered coding it to check them all. Feel free to modify it you want that functionality. EDIT: Chimp modified to loop through all addresses in array.in post >#3 Do be aware that just adding sites is not good enough to ensure the correct data will be returned, you'd have to check the IP regexp function against the data returned from BinaryToString(InetRead($aSites2[$i])) ExternalIP.au3 Edited September 28, 2014 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
DreamVB Posted September 27, 2014 Share Posted September 27, 2014 Nice this will come in us-full I may try and make a GUI that I can call from the system tray with your permission. Thank you for sharing, On Error Resume Pulling Hair Out. Link to comment Share on other sites More sharing options...
Gianni Posted September 27, 2014 Share Posted September 27, 2014 (edited) Get's your external IP address. . . .I acknowledge that only 2 websites are checked from the list, I just could not be bothered coding it to check them all. Feel free to modify it you want that functionality. #include <Array.au3> MsgBox(0, 0, _ExtIP()) Func _ExtIP() Local $UA = HttpSetUserAgent("Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.124 Safari/537.36") Local $aSites2[3] = ["http://checkip.dyndns.org", "http://www.myexternalip.com/raw", "http://bot.whatismyipaddress.com"] _ArrayShuffle($aSites2) ; --- not needed, already randomized by _ArrayShuffle --- ; Local $step = 1 ; Local $Ramdom = Random(0, 1, 1) ; If $Ramdom Then ; $step = -1 ; EndIf ; For $i = $Ramdom To Not $Ramdom Step $step ; ------------------------------------------------------- For $i = 0 To UBound($aSites2) - 1 $sRead = BinaryToString(InetRead($aSites2[$i])) $aRXP = StringRegExp($sRead, "((?:\d{1,3}\.){3}\d{1,3})", 3) If Not @error And $aRXP[0] <> "" Then HttpSetUserAgent($UA) Return $aRXP[0] EndIf Next HttpSetUserAgent($UA) Return 0 EndFunc ;==>_ExtIP Edited September 27, 2014 by Chimp JohnOne 1 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
JohnOne Posted September 28, 2014 Author Share Posted September 28, 2014 (edited) Here's a cheap alternative to get it from google. #include <String.au3> MsgBox(0,0,_ExtGoogleIP()) Func _ExtGoogleIP() Local $UA = HttpSetUserAgent("Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.124 Safari/537.36") $sRead = BinaryToString(InetRead("https://www.google.com/search?q=my+ip+is%3F")) $aRead = _StringBetween($sRead, "div data-hveid", "Your public IP address") If @error Then $UA = HttpSetUserAgent($UA) Return 0 EndIf $aRXP = StringRegExp($aRead[0], "((?:\d{1,3}\.){3}\d{1,3})", 3) If Not @error And $aRXP[0] <> "" Then $UA = HttpSetUserAgent($UA) Return $aRXP[0] EndIf $UA = HttpSetUserAgent($UA) Return 0 EndFunc ;==>_ExtIP Edited September 28, 2014 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
JohnOne Posted September 28, 2014 Author Share Posted September 28, 2014 Or from opendns.com MsgBox(0,0,_ExtOpenDNSIP()) Func _ExtOpenDNSIP() $pid = Run(@ComSpec & " /C " & "nslookup myip.opendns.com resolver1.opendns.com", "", @SW_HIDE, 6) ProcessWaitClose($pid) $str = StdoutRead($pid) $aRXP = StringRegExp($str, "((?:\d{1,3}\.){3}\d{1,3})", 3) If @error Then Return 0 EndIf Return $aRXP[UBound($aRXP) -1] EndFunc ;==>_ExtOpenDNSIP AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
JohnOne Posted September 28, 2014 Author Share Posted September 28, 2014 Or try all of them expandcollapse popup#include <String.au3> #include <Array.au3> MsgBox(0,0,_ExtIP()) Func _ExtIP() Local $myIP = 0 If _ExtOpenDNSIP($myIP) Then Return $myIP EndIf If _ExtGoogleIP($myIP) Then Return $myIP EndIf If _ExtProvidersIP($myIP) Then Return $myIP EndIf Return 0 EndFunc Func _ExtOpenDNSIP(ByRef $ip) $pid = Run(@ComSpec & " /C " & "nslookup myip.opendns.com resolver1.opendns.com", "", @SW_HIDE, 6) ProcessWaitClose($pid) $str = StdoutRead($pid) $aRXP = StringRegExp($str, "((?:\d{1,3}\.){3}\d{1,3})", 3) If @error Then Return 0 EndIf $ip = $aRXP[UBound($aRXP) -1] Return 1 EndFunc ;==>_ExtOpenDNSIP Func _ExtProvidersIP(ByRef $ip) Local $UA = HttpSetUserAgent("Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.124 Safari/537.36") Local $aSites2[3] = ["http://checkip.dyndns.org", "http://www.myexternalip.com/raw", "http://bot.whatismyipaddress.com"] _ArrayShuffle($aSites2) For $i = 0 To UBound($aSites2) - 1 $sRead = BinaryToString(InetRead($aSites2[$i])) $aRXP = StringRegExp($sRead, "((?:\d{1,3}\.){3}\d{1,3})", 3) If Not @error And $aRXP[0] <> "" Then HttpSetUserAgent($UA) $ip = $aRXP[0] Return 1 EndIf Next HttpSetUserAgent($UA) Return 0 EndFunc ;==>_ExtIP Func _ExtGoogleIP(ByRef $ip) Local $UA = HttpSetUserAgent("Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.124 Safari/537.36") $sRead = BinaryToString(InetRead("https://www.google.com/search?q=my+ip+is%3F")) $aRead = _StringBetween($sRead, "div data-hveid", "Your public IP address") If @error Then $UA = HttpSetUserAgent($UA) Return 0 EndIf $aRXP = StringRegExp($aRead[0], "((?:\d{1,3}\.){3}\d{1,3})", 3) If Not @error And $aRXP[0] <> "" Then $UA = HttpSetUserAgent($UA) $ip = $aRXP[0] Return 1 EndIf $UA = HttpSetUserAgent($UA) Return 0 EndFunc ;==>_ExtIP AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
MyDream Posted September 29, 2014 Share Posted September 29, 2014 #include <Inet.au3> Msgbox(0,"External IP",(_INetGetSource('http://icanhazip.com/'))) Link to comment Share on other sites More sharing options...
Gianni Posted September 29, 2014 Share Posted September 29, 2014 (edited) #include <Inet.au3> Msgbox(0,"External IP",(_INetGetSource('http://icanhazip.com/'))) the OP script is an alternative to _INetGetSource() for reasons discussed >here sorry, misunderstood your post Edited September 29, 2014 by Chimp Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now