How can I obtain my internet address?

Just starting out? Need help? Post your questions and find answers here.
User avatar
Vera
Addict
Addict
Posts: 858
Joined: Tue Aug 11, 2009 1:56 pm
Location: Essen (Germany)

Re: How can I obtain my internet address?

Post by Vera »

heartbone wrote:Thanks for the code, but what if he later decides to drop those superfluous brackets?
Than just reduce it further to: :wink:

Code: Select all

EXTADDR$ = ReadString(1)
It's probably best to leave the procedure as is.
Why leave it broken, as it's been heavily optimized in near to no time :D

***
netmaestro wrote:

Code: Select all

ipaddress$ = StringField(result$, 2, #CRLF$+#CRLF$)
and that works fine.
Sorry, not for me, 'cos it'll return the (2nd) date-line. ... I'd have to use:

Code: Select all

ipaddress$ = StringField(result$, 8, #CRLF$+#CRLF$)
or this, following Thunder93 's suggestion:

Code: Select all

ipaddress$ = Mid(Result$, FindString(Result$, #CRLF$+#CRLF$,1)+4)
~ nice ava Image ~
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: How can I obtain my internet address?

Post by Thunder93 »

Edited...

You shouldn't be seeing It returned to date-line... Please see my following post.
Last edited by Thunder93 on Tue Dec 23, 2014 11:50 pm, edited 1 time in total.
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: How can I obtain my internet address?

Post by Thunder93 »

What if you had it like..

Code: Select all

        If ReceiveNetworkData(connect, @result$, 1024)
          ipaddress$ = Trim(StringField(result$, 2, #CRLF$+#CRLF$))
        Else
? Keeping netmaestro style. :p
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
User avatar
Vera
Addict
Addict
Posts: 858
Joined: Tue Aug 11, 2009 1:56 pm
Location: Essen (Germany)

Re: How can I obtain my internet address?

Post by Vera »

Thunder93 wrote:What if you had it like..
Nope, I'll still get an empty line (just a linebreak) followed by the date-line.
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: How can I obtain my internet address?

Post by Thunder93 »

I forgot... Unicode. You running it with Unicode mode? Try the following.

Code: Select all

        If ReceiveNetworkData(connect, @result$, 1024)
          result$ = Trim(PeekS(@result$, -1, #PB_UTF8))          
          ipaddress$ = StringField(result$, 2, #CRLF$+#CRLF$)
        Else
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
User avatar
Vera
Addict
Addict
Posts: 858
Joined: Tue Aug 11, 2009 1:56 pm
Location: Essen (Germany)

Re: How can I obtain my internet address?

Post by Vera »

Well, I already tested #PB_UTF8, likewise switching between comiling with/without unicode mode.
The debug looks ok, like a saved file does: the result-lines aren't seperated:

Code: Select all

HTTP/1.1 200 OK                      ; result$
 
Date: Tue, 23 Dec 2014 23:26:29 GMT

Server: Apache

X-Powered-By: PHP/5.4.25

Content-Length: 12

Content-Type: text/html



xx.xxx.xx.xx                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
                                                                ; ipaddress$
Date: Tue, 23 Dec 2014 23:26:29 GMT
ps: after pasting this in here, I see those double linebreaks (in this posting).
The downloaded file is in DOS mode (I'm on Linux), but even changing it in the request to ISO-8859-1, DOS, would not make a change.
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: How can I obtain my internet address?

Post by Thunder93 »

This or something similar should work.

Code: Select all

        If ReceiveNetworkData(connect, @result$, 1024)
          result$ = ReplaceString(PeekS(@result$, -1, #PB_Ascii), " "+#TAB$, #CRLF$)
          ipaddress$ = StringField(Result$, 2, #CRLF$+#CRLF$)
        Else
The end of the header section is indicated by an empty field, resulting in the transmission of two consecutive CR-LF pairs. Historically, long lines could be folded into multiple lines; continuation lines are indicated by the presence of a space (SP) or horizontal tab (HT) as the first character on the next line. This folding is now deprecated.
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
User avatar
Vera
Addict
Addict
Posts: 858
Joined: Tue Aug 11, 2009 1:56 pm
Location: Essen (Germany)

Re: How can I obtain my internet address?

Post by Vera »

Hello Thunder93, I'm completely at loss what to test anymore.

Your latest example also doesn't make a change. But I got the idea to debug the linefeed-characters.

Code: Select all

result$ = Trim(PeekS(@result$, -1, #PB_Ascii))
Debug CountString(result$, #CRLF$)  ; 7
Debug CountString(result$, #CR$)    ; 7
Debug CountString(result$, #LF$)    ; 7
Debug CountString(result$, #TAB$)  ; 0
But even if I'd remove e.g. #LF$ and definitely only have seven single #CR$ left over, the ipaddress$ will still return the 2nd line from the result.

Code: Select all

result$ = ReplaceString(PeekS(@result$, -1, #PB_Ascii), #LF$, "") 
Debug CountString(result$, #CRLF$)  ; 0
Debug CountString(result$, #CR$)    ; 7
Debug CountString(result$, #LF$)    ; 0

ipaddress$ = StringField(result$, 2, #CR$+#CR$)  ; Date: Wed, 24 Dec 2014...
User avatar
heartbone
Addict
Addict
Posts: 1058
Joined: Fri Apr 12, 2013 1:55 pm
Location: just outside of Ferguson

Re: How can I obtain my internet address?

Post by heartbone »

I've dug out the old crossover cable and made a two computer router-less LAN.
The real life situation of no internet connectivity made this a dog of a procedure.
(waiting for the nine timeouts) Here's a fix.

Code: Select all

Procedure.S GetExternalIPAddress(TIMEOUT)
; RETURNS A STRING CONTAINING THE CURRENT IPv4 EXTERNAL ADDRESS.
; THIS PROCEDURE WILL STOP CHECKING WEBSITES AFTER TIMEOUT MILLISECONDS IMMEDIATELY EXIT
; 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/
   EXTADDR$= "" 
   If TIMEOUT < 1 : TIMEOUT= 100 : EndIf
   STOPTIME= ElapsedMilliseconds()+ TIMEOUT
   WHICH= Random(8)+ 1 : START= WHICH 
   Repeat
      CURRTIME= ElapsedMilliseconds()
      Select WHICH
         Case 1
            If CURRTIME < STOPTIME
               If ReceiveHTTPFile("http://ip.gwhois.org/","IPADDRESS")
                  ReadFile(1,"IPADDRESS") : EXTADDR$= ReadString(1) : CloseFile(1) : DeleteFile("IPADDRESS")
               EndIf
            EndIf
         Case 2
            If CURRTIME < STOPTIME
               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
            EndIf
         Case 3
            If CURRTIME < STOPTIME
               If ReceiveHTTPFile("http://ipecho.net/plain","IPADDRESS")
                  ReadFile(1,"IPADDRESS") : EXTADDR$= ReadString(1) : CloseFile(1) : DeleteFile("IPADDRESS")
               EndIf
            EndIf
         Case 4
            If CURRTIME < STOPTIME
               EXTADDR$= StringField(GetHTTPHeader("http://hex0rs.coderbu.de/Sonstiges/ShowMyIp12.php"),2,Chr(34))
            EndIf 
        Case 5
            If CURRTIME < STOPTIME
               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
            EndIf
         Case 6
            If CURRTIME < STOPTIME
               If ReceiveHTTPFile("http://lloydsplace.com/whatsmyip.php","IPADDRESS")
                  ReadFile(1,"IPADDRESS") : EXTADDR$= ReadString(1) : CloseFile(1) : DeleteFile("IPADDRESS")
               EndIf
            EndIf
         Case 7
            If CURRTIME < STOPTIME
               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
            EndIf
         Case 8
            If CURRTIME < STOPTIME
               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
            EndIf
         Case 9
            If CURRTIME < STOPTIME
               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
            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
Currently I'm passing in a value of 4000, and probably that's a bit too long to wait, but I'll be conservative and leave it.
Keep it BASIC.
User avatar
heartbone
Addict
Addict
Posts: 1058
Joined: Fri Apr 12, 2013 1:55 pm
Location: just outside of Ferguson

Re: How can I obtain my internet address?

Post by heartbone »

Yes it is quite useful and I'm using it everyday in more and more of my programs.
I hope that I'm not being too obsessive here, I've added a couple of optimizations,
and fixed the bug in cases 2 & 4 where the temporary file was not being deleted.

Code: Select all

Procedure.S GetExternalIPAddress(TIMEOUT)
; RETURNS A STRING CONTAINING THE CURRENT IPv4 EXTERNAL ADDRESS.
; THIS PROCEDURE WILL STOP CHECKING WEBSITES AFTER TIMEOUT MILLISECONDS IMMEDIATELY EXIT
; 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$= ""
   If TIMEOUT < 1 : TIMEOUT= 10 : EndIf
   STOPTIME= ElapsedMilliseconds()+ TIMEOUT
   Repeat
      If ElapsedMilliseconds() < STOPTIME
         Select WHICH
            Case 1
               If ReceiveHTTPFile("http://ip.gwhois.org/","IPADDRESS")
                  ReadFile(1,"IPADDRESS") : EXTADDR$= ReadString(1) 
               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)
               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
               EndIf
            Case 6
               If ReceiveHTTPFile("http://lloydsplace.com/whatsmyip.php","IPADDRESS")
                  ReadFile(1,"IPADDRESS") : EXTADDR$= ReadString(1)
               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
               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
               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
               EndIf
         EndSelect
         If IsFile(1) 
            CloseFile(1) : DeleteFile("IPADDRESS")
         EndIf
         If CountString(EXTADDR$,".")<>3 Or Len(EXTADDR$)<7 Or Len(EXTADDR$)>15 : EXTADDR$= "" : EndIf
      EndIf
      WHICH +1 : If WHICH=10 : WHICH= 1 : EndIf
   Until EXTADDR$<>"" Or WHICH=START
   ProcedureReturn EXTADDR$
EndProcedure
Unfortunately, AVIRA started to object to the object again.
Because I doubt if I'll be changing it anymore, I'm going to add my little ShowMyIPs.exe utility to AVIRA's exceptions list.

Code: Select all

InitNetwork() : ExamineIPAddresses() : EXTADDR$= GetExternalIPAddress(4000)
If EXTADDR$<>""
   BUFF$= "EXTERNAL IPv4 = "+EXTADDR$
Else
   BUFF$= "UNABLE TO RETRIEVE EXTERNAL ADDRESS"
EndIf
MessageRequester(BUFF$,"      INTERNAL LAN ADDRESS = "+IPString(NextIPAddress())+"      ",#PB_MessageRequester_Ok)
Keep it BASIC.
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: How can I obtain my internet address?

Post by JHPJHP »

Windows Only ?? (not tested on any other OS)
- uses DNS as opposed to HTTP

Code: Select all

Result = RunProgram("nslookup", "myip.opendns.com resolver1.opendns.com", "", #PB_Program_Hide | #PB_Program_Open | #PB_Program_Read)

If Result
  Dim IPAddress.s(0)

  While ProgramRunning(Result)
    If AvailableProgramOutput(Result)
      regEx = CreateRegularExpression(#PB_Any, "\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}")
      ExtractRegularExpression(regEx, ReadProgramString(Result), IPAddress())
      FreeRegularExpression(regEx)
    EndIf
  Wend
  CloseProgram(Result)
  Debug IPAddress(0)
EndIf
NB*: Included in my Services, Stuff, and Shellhook post.
User avatar
heartbone
Addict
Addict
Posts: 1058
Joined: Fri Apr 12, 2013 1:55 pm
Location: just outside of Ferguson

Re: How can I obtain my internet address?

Post by heartbone »

http://hex0rs.coderbu.de/Sonstiges/ShowMyIp12.php
http://ipecho.net/plain
http://www.whatismyip.com/
The turnover rate is ridiculous.

Also, replacing the four instances of

Code: Select all

                     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)
with

Code: Select all

x=0
causes the Winx86 compiled executable to shrink from 196 Kb to 18.5 Kb.

At this point my optimum game procedure has been reduced to this.

Code: Select all

Procedure.S GetExternalIPAddress(TIMEOUT)
; RETURNS A STRING CONTAINING THE CURRENT IPv4 EXTERNAL ADDRESS.
; THIS PROCEDURE WILL STOP CHECKING WEBSITES AFTER TIMEOUT MILLISECONDS IMMEDIATELY EXIT
; 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://lloydsplace.com/whatsmyip.php
; WHICH=4 EXTRACT IP ADDRESS FROM http://www.realip.info/api/p/realip.php
   WHICH= Random(3)+ 1 : START= WHICH
   EXTADDR$= "" : TEMPFILE$= GetTemporaryDirectory()+"IPADDRESS"
   If TIMEOUT < 1 : TIMEOUT= 10 : EndIf
   STOPTIME= ElapsedMilliseconds()+ TIMEOUT
   Repeat
      If ElapsedMilliseconds() < STOPTIME
         Select WHICH
            Case 1
               If ReceiveHTTPFile("http://ip.gwhois.org/",TEMPFILE$)
                  ReadFile(1,TEMPFILE$) : EXTADDR$= ReadString(1) 
               EndIf
            Case 2
               If ReceiveHTTPFile("http://checkip.dyndns.org",TEMPFILE$)
                  ReadFile(1,TEMPFILE$) : HEADER$= ReadString(1) 
                  STIND= FindString(HEADER$, "Current IP Address:", 1)+ 20
                  IND= FindString(HEADER$,"</body></html>",1)- STIND
                  If IND > 0 : EXTADDR$ = Mid(HEADER$,STIND,IND) : EndIf
               EndIf
            Case 3
               If ReceiveHTTPFile("http://lloydsplace.com/whatsmyip.php",TEMPFILE$)
                  ReadFile(1,TEMPFILE$) : EXTADDR$= ReadString(1)
               EndIf
            Case 4
               If ReceiveHTTPFile("http://www.realip.info/api/p/realip.php",TEMPFILE$)
                  ReadFile(1,TEMPFILE$) : EXTADDR$= ReadString(1) 
                  TBUFF$=  Mid(EXTADDR$,8) : EXTADDR$= Mid(TBUFF$,1,Len(TBUFF$)-2)
               EndIf
         EndSelect
         If IsFile(1) : CloseFile(1) : DeleteFile(TEMPFILE$) : EndIf
         If CountString(EXTADDR$,".")<>3 Or Len(EXTADDR$)<7 Or Len(EXTADDR$)>15 : EXTADDR$= "" : EndIf
      EndIf
      WHICH +1 : If WHICH=5 : WHICH= 1 : EndIf
   Until EXTADDR$<>"" Or WHICH=START
   ProcedureReturn EXTADDR$
EndProcedure
If I could find just a few more sites that return a simple one line text page, then I'd feel better about not needing to recompile any program that uses this procedure after a few short months.
If anyone knows of other websites that return the IP address in plain text, kindly post a link here.
I've unsuccessfully tried to extract from corz.org/ip/ which is limited to one hit from a site per minute, but something stops ReceiveHTTPFile().
Keep it BASIC.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8422
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: How can I obtain my internet address?

Post by netmaestro »

I had to take my php script down. I get thousands of requests per day on my poor little server for this script, all from what looks like less than six users. Someone has it automated and my setup just isn't designed for that kind of load.
BERESHEIT
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: How can I obtain my internet address?

Post by Dude »

heartbone wrote:If anyone knows of other websites that return the IP address in plain text, kindly post a link here.
If you've got a website with PHP, just throw this tiny code into it and you're done. Save it as "ip.php" on your website, then just access it with "www.website.com/ip.php" to get your IP address as plain text. It can't get any more simple. :)

Code: Select all

<?php
echo $_SERVER["REMOTE_ADDR"];
?>
User avatar
heartbone
Addict
Addict
Posts: 1058
Joined: Fri Apr 12, 2013 1:55 pm
Location: just outside of Ferguson

Re: How can I obtain my internet address?

Post by heartbone »

netmaestro wrote:I had to take my php script down. I get thousands of requests per day on my poor little server for this script, all from what looks like less than six users. Someone has it automated and my setup just isn't designed for that kind of load.
It seems that there are always a few bad players.
I'll substitute it with this one.
http://api.ipify.org/
from these guys.
https://www.ipify.org/
Keep it BASIC.
Post Reply