How can I obtain my internet address?

Just starting out? Need help? Post your questions and find answers here.
User avatar
Keya
Addict
Addict
Posts: 1891
Joined: Thu Jun 04, 2015 7:10 am

Re: How can I obtain my internet address?

Post by Keya »

heartbone that looks like the Get IP Address site we've all been waiting for heehee, all the others can move to secondary now :D
User avatar
tj1010
Enthusiast
Enthusiast
Posts: 621
Joined: Mon Feb 25, 2013 5:51 pm
Location: US or Estonia
Contact:

Re: How can I obtain my internet address?

Post by tj1010 »

If I remember correctly the WAN ISP gateway IP is in your modem UpNp data and ARP table.
The truth hurts.
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 »

Keya wrote:heartbone that looks like the Get IP Address site we've all been waiting for heehee, all the others can move to secondary now :D
I'll set the function to randomly access that new site 4/7 the time, and randomly retrieve from one the other three sites at a rate of 1 of 7 calls.
That way the function is not dependent on just one site, and gives most of the action to the new site, and hope that solution will continue work for as long as IPv4 is still used.

Code: Select all

Procedure.S GetExternalIPAddress(TIMEOUT)
; RETURNS A STRING CONTAINING THE CURRENT IPv4 EXTERNAL ADDRESS.
; A PREVIOUS CALL TO InitNetwork() IS REQUIRED.
; WILL STOP CHECKING WEBSITES AFTER TIMEOUT (IN MILLISECONDS).
; NURL GETS SET TO RANDOM INTEGER FROM 1 THROUGH 7.
; NURL=1 EXTRACT IP ADDRESS FROM http://ip.gwhois.org/
; NURL=2 EXTRACT IP ADDRESS FROM http://checkip.dyndns.org
; NURL=3 EXTRACT IP ADDRESS FROM http://www.realip.info/api/p/realip.php
; NURL=4,5,6,7 EXTRACT IP ADDRESS FROM http://api.ipify.org/
; ON AVERAGE api.ipify.org IS USED FOUR TIMES IN SEVEN CALLS.
   NURL= Random(6)+ 1 : START= NURL
   EXTADDR$= "" : TEMPFILE$= GetTemporaryDirectory()+"IPADDRESS"
   If TIMEOUT < 1 : TIMEOUT= 10 : EndIf
   STOPTIME= ElapsedMilliseconds()+ TIMEOUT
   Repeat
      If ElapsedMilliseconds() < STOPTIME
         Select NURL
            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://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
            Case 4, 5, 6, 7
               If ReceiveHTTPFile("http://api.ipify.org/",TEMPFILE$)
                  ReadFile(1,TEMPFILE$) : EXTADDR$= ReadString(1)
               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
      NURL +1 : If NURL=8 : NURL= 1 : EndIf
   Until EXTADDR$<>"" Or NURL=START
   ProcedureReturn EXTADDR$
EndProcedure
Keep it BASIC.
Post Reply