CODICE
#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <Array.au3> ; Required only for _ArrayDisplay(), but not the UDF's
MsgBox(0, "Public IP Address - _GetIP()", _GetIP()) ; Improved _GetIP()
MsgBox(0, "Public IP Address - _GetIP_New()", _GetIP_New()) ; Alternative _GetIP()
Global $Array = _GetIPEx()
_ArrayDisplay($Array, "Public IP Address - _GetIPEx()")
$Array = _GetISP()
_ArrayDisplay($Array, "Public IP Address - _GetISP()")
$Array = _GetISP_New()
_ArrayDisplay($Array, "Public IP Address - _GetISP_New()")
$Array = _GetISP_New_()
_ArrayDisplay($Array, "Public IP Address - _GetISP_New_()")
MsgBox(0, "Provider Name - _GetProvider()", _GetProvider())
; #FUNCTION# =========================================================================================================
; Name...........: _GetIP
; Description ...: Retrieves the Public IP Address of a Network/Computer.
; Syntax.........: _GetIP()
; Parameters ....: None
; Requirement(s).: v3.3.2.0 or higher
; Return values .: Success - Returns Public IP Address.
; Failure - Returns -1 & sets @error = 1
; Author ........: guinness
; Example........; Yes
;=====================================================================================================================
Func _GetIP()
Local $bRead, $sRead, $sReturn
$bRead = InetRead("http://checkip.dyndns.org/")
$sRead = BinaryToString($bRead)
$sReturn = StringRegExp($sRead, '(?s)(?i)<body>Current IP Address: (.*?)</body>', 3)
If Not @error Then Return $sReturn[0]
$bRead = InetRead("http://www.whatismyip.com/automation/n09230945.asp") ; http://forum.whatismyip.com/f14/our-automation-rules-t241/
$sRead = BinaryToString($bRead)
If Not @error Then Return $sRead
Return SetError(1, 1, -1)
EndFunc ;==>_GetIP
; #FUNCTION# =========================================================================================================
; Name...........: _GetIP
; Description ...: Retrieves the Public IP Address of a Network/Computer.
; Syntax.........: _GetIP()
; Parameters ....: None
; Requirement(s).: v3.3.2.0 or higher
; Return values .: Success - Returns Public IP Address.
; Failure - Returns -1 & sets @error = 1
; Author ........: guinness
; Example........; Yes
;=====================================================================================================================
Func _GetIP_New()
Local $bRead, $sRead, $sReturn
$bRead = InetRead("http://api.hostip.info/?ip=")
$sRead = BinaryToString($bRead)
$sReturn = StringRegExp($sRead, "<ip>(.*?)</ip>", 3)
If Not @error Then Return $sReturn[0]
$bRead = InetRead("http://www.checkingtools.com/ip_check")
$sRead = BinaryToString($bRead)
$sReturn = StringRegExp($sRead, '(?s)(?i)<a href="/\?ip=(.*?)">', 3)
If Not @error Then Return $sReturn[0]
$bRead = InetRead("http://www.opendns.com/")
$sRead = BinaryToString($bRead)
$sReturn = StringRegExp($sRead, '(?s)(?i)<p>Your current IP is <b>(.*?)</b>.</p>', 3)
If Not @error Then Return $sReturn[0]
Return SetError(1, 1, -1)
EndFunc ;==>_GetIP_New
; #FUNCTION# =========================================================================================================
; Name...........: _GetIPEx
; Description ...: Retrieves the Public IP Address of a Network/Computer with additional details.
; Syntax.........: _GetIPEx([$sIPAddress])
; Parameters ....: $sIPAddress - [Optional] A valid IP Address e.g. 192.168.0.1
; Requirement(s).: v3.3.2.0 or higher
; Return values .: Success - Returns a 1D Array. $Array[4] = [Number of Items, IP Address, Country name, Country code]
; Failure - Returns -1 & sets @error = 1
; Author ........: guinness
; Example........; Yes
;=====================================================================================================================
Func _GetIPEx($sIPAddress = "")
Local $aXML[4] = [3, "ip", "countryName", "countryAbbrev"], $bRead, $sRead, $sReturn
$bRead = InetRead("http://api.hostip.info/?ip=" & $sIPAddress)
If @error Then Return SetError(1, 1, -1)
$sRead = BinaryToString($bRead)
For $A = 1 To $aXML[0]
$sReturn = StringRegExp($sRead, "<(?i)" & $aXML[$A] & ">(.*?)</(?i)" & $aXML[$A] & ">", 3)
$aXML[$A] = $sReturn[0]
Next
If Not @error Then Return $aXML
Return SetError(1, 1, -1)
EndFunc ;==>_GetIPEx
; #FUNCTION# =========================================================================================================
; Name...........: _GetISP
; Description ...: Retrieves the Public IP Address of a Network/Computer with additional details.
; Syntax.........: _GetISP([$sIPAddress])
; Parameters ....: $sIPAddress - [Optional] A valid IP Address e.g. 192.168.0.1
; Requirement(s).: v3.3.2.0 or higher
; Return values .: Success - Returns a 1D Array. $Array[9] = [Number of Items, IP Address, ISP, ISP location, Country, IPv4 Dotted Binary Notation, _
; IPv4 Dotted Octal Notation, IPv4 Dotted Decimal Notation, IPv4 Dotted Hexadecimal Notation]
; Failure - Returns -1 & sets @error = 1
; Author ........: guinness
; Example........; Yes
;=====================================================================================================================
Func _GetISP($sIPAddress = "")
Local $aXML[9] = [8, "ipspan", "networkspan", "addressspan", "countryspan", "ipbinaryspan", "ipoctalspan", "ipdecimalspan", "iphexadecimalspan"], $bRead, $sRead, $sReturn
$bRead = InetRead("http://www.ip-details.com/ip-search/" & $sIPAddress)
If @error Then Return SetError(1, 1, -1)
$sRead = BinaryToString($bRead)
$sReturn = StringRegExp($sRead, '(?s)(?i)<!-- start content -->(.*?)<!-- end content -->', 3)
$sRead = $sReturn[0]
For $A = 1 To $aXML[0]
$sReturn = StringRegExp($sRead, '(?i)<span id="' & $aXML[$A] & '">(.*?)</span>', 3)
If @error Then ContinueLoop
$aXML[$A] = $sReturn[0]
Next
If Not @error Then Return $aXML
Return SetError(1, 1, -1)
EndFunc ;==>_GetISP
; #FUNCTION# =========================================================================================================
; Name...........: _GetISP
; Description ...: Retrieves the Public IP Address of a Network/Computer with additional details.
; Syntax.........: _GetISP()
; Requirement(s).: v3.3.2.0 or higher
; Return values .: Success - Returns a 1D Array. $Array[5] = [Number of Items, IP Address, Country name, Host Name, ISP]
; Failure - Returns -1 & sets @error = 1
; Author ........: guinness
; Example........; Yes
;=====================================================================================================================
Func _GetISP_New()
Local $aXML[5] = [4]
Local $bRead, $sRead, $sReturn
$bRead = InetRead("http://ip.xxoo.net/")
$sRead = BinaryToString($bRead)
$sReturn = StringRegExp($sRead, '(?s)(?i)<B>IP Address:</B>(.*?)<script type="text/javascript">', 3)
If @error Then Return SetError(1, 1, -1)
$sRead = $sReturn[0]
$sReturn = StringRegExp($sRead, '(?s)(?i)<div align="left">(.*?)</div>', 3)
If @error Then Return SetError(1, 1, -1)
$sRead = $sReturn
For $A = 1 To $aXML[0]
If $A - 1 = 1 Then
$sReturn = StringRegExp($sRead[$A - 1], '(?s)(?i)\A(.*?) ', 3)
If @error Then ContinueLoop
$sRead[$A - 1] = $sReturn[0]
EndIf
$aXML[$A] = $sRead[$A - 1]
Next
If Not @error Then Return $aXML
Return SetError(1, 1, -1)
EndFunc ;==>_GetISP_New
; #FUNCTION# =========================================================================================================
; Name...........: _GetISP
; Description ...: Retrieves the Public IP Address of a Network/Computer with additional details.
; Syntax.........: _GetISP()
; Requirement(s).: v3.3.2.0 or higher
; Return values .: Success - Returns a 1D Array. $Array[10] = [Number of Items, IP Address, AS number, ASN number, ISP name, ISP address, Net address, ISP description, City, Country]
; Failure - Returns -1 & sets @error = 1
; Author ........: guinness
; Example........; Yes
;=====================================================================================================================
Func _GetISP_New_()
Local $aXML[10] = [9, "ip", "as", "asn", "asname", "ptr", "net", "netdescr", "city", "country"], $bRead, $sRead, $sReturn
$bRead = InetRead("http://www.robtex.com/ipinfo.js")
$sRead = BinaryToString($bRead)
For $A = 1 To $aXML[0]
$sReturn = StringRegExp($sRead, '(?s)(?i)if\(m=="' & $aXML[$A] & '"\) a\.innerHTML="(.*?)"', 3)
If @error Then ContinueLoop
$aXML[$A] = $sReturn[0]
Next
If Not @error Then Return $aXML
Return SetError(1, 1, -1)
EndFunc ;==>_GetISP_New_
; #FUNCTION# =========================================================================================================
; Name...........: _GetProvider
; Description ...: Retrieves the ISP provider name.
; Syntax.........: _GetProvider()
; Parameters ....: None
; Requirement(s).: v3.3.2.0 or higher
; Return values .: Success - Returns ISP provider name.
; Failure - Returns -1 & sets @error = 1
; Author ........: guinness
; Example........; Yes
;=====================================================================================================================
Func _GetProvider()
Local $bRead, $sRead, $sReturn
$bRead = InetRead("http://www.robtex.com/ipinfo.js")
$sRead = BinaryToString($bRead)
$sReturn = StringRegExp($sRead, '(?s)(?i)if\(m=="asname"\) a\.innerHTML="(.*?)"', 3)
If Not @error Then Return $sReturn[0]
Return SetError(1, 1, -1)
EndFunc ;==>_GetProvider