???Vera wrote:I wouldn't consider 6 years availability to be unstableheartbone wrote:HeX0R, although yours is by far the easiest to implement, I consider it to be the least stable as far as longevity, which is why it's used third.
But I'm thinking that perhaps I have it backwards.
Vera, if you look at the original post from 4 years ago, that site (http://h3x0r.ath.cx/Sonstiges/ShowMyIp12.php) is no longer there.
And thanks for your contribution to the procedure.Btw: thanks for your collection and inspiration how to get it.
Here's a further variation you might like to add:
I slightly modified your loop exit logic to remove the Break statement.
Code: Select all
Procedure.s GetExternalIPAddress()
; RETURNS A STRING CONTAINING THE CURRENT (IPv4} EXTERNAL IP ADDRESS.
; RETRIEVED FROM ANY ONE OF 9 WEBSITES
; ALL 9 TESTED GOOD Monday, December 22, 2014. 6:57-6:59 PM CST
; A PREVIOUS CALL TO InitNetwork() IS REQUIRED.
; WHICH=1 EXTRACT IP ADDRESS FROM http://ip.gwhois.org/
; WHICH=2 EXTRACT IP ADDRESS FROM http://checkip.dyndns.org
; WHICH=3 EXTRACT IP ADDRESS FROM http://ipecho.net/plain
; WHICH=4 EXTRACT IP ADDRESS FROM http://hex0rs.coderbu.de/Sonstiges/ShowMyIp12.php
; WHICH=5 EXTRACT IP ADDRESS FROM http://www.cmyip.com
; WHICH=6 EXTRACT IP ADDRESS FROM http://lloydsplace.com/whatsmyip.php
; WHICH=7 EXTRACT IP ADDRESS FROM http://www.realip.info/api/p/realip.php
; WHICH=8 EXTRACT IP ADDRESS FROM http://www.iplocation.net/
; WHICH=9 EXTRACT IP ADDRESS FROM http://www.whatsmyip.net/
WHICH= Random(8)+ 1 : START= WHICH : EXTADDR$= ""
Repeat
Select WHICH
Case 1
If ReceiveHTTPFile("http://ip.gwhois.org/","IPADDRESS")
ReadFile(1,"IPADDRESS") : EXTADDR$= ReadString(1) : CloseFile(1) : DeleteFile("IPADDRESS")
EndIf
Case 2
HEADER$= GetHTTPHeader("http://checkip.dyndns.org")
STIND= FindString(HEADER$, "Current IP Address:", 1)+ 20
IND= FindString(HEADER$,"</body></html>",1)- STIND
If IND > 0 : EXTADDR$ = Mid(HEADER$,STIND,IND) : EndIf
Case 3
If ReceiveHTTPFile("http://ipecho.net/plain","IPADDRESS")
ReadFile(1,"IPADDRESS") : EXTADDR$= ReadString(1) : CloseFile(1) : DeleteFile("IPADDRESS")
EndIf
Case 4
EXTADDR$= StringField(GetHTTPHeader("http://hex0rs.coderbu.de/Sonstiges/ShowMyIp12.php"),2,Chr(34))
Case 5
If ReceiveHTTPFile("http://www.cmyip.com","IPADDRESS")
ReadFile(1,"IPADDRESS")
Dim sIP.s(0) : sIP(0) = ""
While Eof(1) = 0 And sIP(0) = ""
EXTADDR$= ReadString(1)
If FindString(EXTADDR$,"My IP Address",1)
CreateRegularExpression(0,"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}")
If ExtractRegularExpression(0,EXTADDR$,sIP()) > 0 : EXTADDR$= sIP(0) : EndIf
FreeRegularExpression(0)
EndIf
Wend
CloseFile(1) : DeleteFile("IPADDRESS")
EndIf
Case 6
If ReceiveHTTPFile("http://lloydsplace.com/whatsmyip.php","IPADDRESS")
ReadFile(1,"IPADDRESS")
Dim sIP.s(0) : sIP(0) = ""
While Eof(1) = 0 And sIP(0) = ""
EXTADDR$= ReadString(1)
CreateRegularExpression(0,"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}")
If ExtractRegularExpression(0,EXTADDR$,sIP()) > 0 : EXTADDR$= sIP(0) : EndIf
FreeRegularExpression(0)
Wend
CloseFile(1) : DeleteFile("IPADDRESS")
EndIf
Case 7
If ReceiveHTTPFile("http://www.realip.info/api/p/realip.php","IPADDRESS")
ReadFile(1,"IPADDRESS")
Dim sIP.s(0) : sIP(0) = ""
While Eof(1) = 0 And sIP(0) = ""
EXTADDR$= ReadString(1)
CreateRegularExpression(0,"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}")
If ExtractRegularExpression(0,EXTADDR$,sIP()) > 0 : EXTADDR$= sIP(0) : EndIf
FreeRegularExpression(0)
Wend
CloseFile(1) : DeleteFile("IPADDRESS")
EndIf
Case 8
If ReceiveHTTPFile("http://www.iplocation.net/","IPADDRESS")
ReadFile(1,"IPADDRESS")
Dim sIP.s(0) : sIP(0) = ""
While Eof(1) = 0 And sIP(0) = ""
EXTADDR$= ReadString(1)
If FindString(EXTADDR$,"Your IP Address is",1)
CreateRegularExpression(0,"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}")
If ExtractRegularExpression(0,EXTADDR$,sIP()) > 0 : EXTADDR$= sIP(0) : EndIf
FreeRegularExpression(0)
EndIf
Wend
CloseFile(1) : DeleteFile("IPADDRESS")
EndIf
Case 9
If ReceiveHTTPFile("http://www.whatsmyip.net/","IPADDRESS")
ReadFile(1,"IPADDRESS")
Dim sIP.s(0) : sIP(0) = ""
While Eof(1) = 0 And sIP(0) = ""
EXTADDR$= ReadString(1)
If FindString(EXTADDR$," Address is ",1)
CreateRegularExpression(0,"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}")
If ExtractRegularExpression(0,EXTADDR$,sIP()) > 0 : EXTADDR$= sIP(0) : EndIf
FreeRegularExpression(0)
EndIf
Wend
CloseFile(1) : DeleteFile("IPADDRESS")
EndIf
EndSelect
If CountString(EXTADDR$,".")<>3 Or Len(EXTADDR$)<7 Or Len(EXTADDR$)>15 : EXTADDR$= "" : EndIf
WHICH +1 : If WHICH=10 : WHICH= 1 : EndIf
Until EXTADDR$<>"" Or WHICH=START
ProcedureReturn EXTADDR$
EndProcedure
Thanks for the addition Marlin.Marlin wrote:OK, now I actually got to provide some code about getting the external IP address from the router using upnp.
I even tested it, and it works fine here.
{SNIP}
Although I'm still not convinced that code is not dependent on an external website,
I'd consider using your code as a separate fallback procedure to be called in the case the above GetExternalIPAddress() procedure returns a null string.