Page 2 of 2

Posted: Sat Jul 16, 2005 4:37 am
by NoahPhense
Max. wrote:
TerryHough wrote:Care to share your code?
It is basically what you posted already.
Here's the code for the lib:

Code: Select all

; By NoahPhense
; Date: 27. June 2004 
; note: Thought I saw something like this somewhere, but couldn't 
;       find it, so I modified some old code.  This code is meant 
;       to rip pages.  So I'm just parsing the ripped page. 


;- PROCEDURES
Procedure.s OpenURL(Url.s, OpenType.b)
  ; OpenURL procedure by ricardo 2003
  isLoop.b=1 
  INET_RELOAD.l=$80000000 
  hInet.l=0: hURL.l=0: Bytes.l=0 
  Buffer.s=Space(2048) 
  hInet = InternetOpen_("PB@INET", OpenType, #NULL, #NULL, 0) 
  hURL = InternetOpenUrl_(hInet, Url, #NULL, 0, INET_RELOAD, 0) 
  Repeat 
    Delay(1) 
    InternetReadFile_(hURL, @Buffer, Len(Buffer), @Bytes) 
    If Bytes = 0 
      isLoop=0 
    Else 
      res.s = res + Left(Buffer, Bytes) 
    EndIf 
  Until isLoop=0 
  InternetCloseHandle_(hURL) 
  InternetCloseHandle_(hInet) 
  ProcedureReturn res 
EndProcedure 

ProcedureDLL.s lbdt_GetIP_Ver(); returns a string with the current version
  ver.s = "GetIP v1.0 beta"
  ProcedureReturn ver
EndProcedure

ProcedureDLL.s lbdt_GetIP_Contact(); returns a contact email address
  contact.s = "dev.team@liquidbuzz.com"
  ProcedureReturn contact
EndProcedure

;- SITES
ProcedureDLL.s lbdt_GetIP(); returns a string with your external IP Address
  site1_rtn.s = "" ; clear for next run
  URL$ = "http://www.ipaddressworld.com"
  HTML$ = OpenURL(URL$, 1) 
  q.s = Chr(34) 
  mainString.s = "<font face="+q+"Verdana, Arial, Helvetica, Sans-serif"+q+" size="+q+"+6"+q+">"
  ; Debug HTML$

  mod_1 = FindString(HTML$, mainString, 1) 
  mod_2.s = Mid(Html$, mod_1, 100) 
  mod_4.s = Mid(mod_2, 62, 15) 
  mod_5 = FindString(mod_4, "<", 1) 
  mod_6.s = Mid(mod_4, 1, mod_5-1) 

  For k=1 To 4
    lcl.s = StringField(mod_6, k, ".")
    If Val(lcl) >= 1
      ; -- do nothing
    Else
      site1_rtn = "bad site"
    EndIf
  Next 

  If site1_rtn = ""
    site1_rtn = mod_6
  EndIf
  
  ProcedureReturn site1_rtn
EndProcedure
Enjoy!

- np

Posted: Thu Jul 21, 2005 6:06 pm
by Straker
Good code np.

However, I have a full 15 char IP address so the code didn't work for me until I changed the following line in lbdt_GetIP() from

mod_4.s = Mid(mod_2, 62, 15)

to

mod_4.s = Mid(mod_2, 62, 16)

because the mod_5 line was not finding the "<"

Thanks again.

Cheers.

Posted: Thu Jul 21, 2005 7:49 pm
by TerryHough
Also see this post related to this subject.
viewtopic.php?t=15924&highlight=visible

This is a bit easier because the only thing returned in the HTML page is
the IP Address aleady formatted. You only need to download 15
characters, although I am doing 20 for safety.

Put the PHP code on your known reliable website (that supports PHP) as
"IP.php" and then call it "http:\\your.ownwebsite.com/IP.php" and save
Gansta93 the bandwidth.

However, if you want to parse through the HTML searching for it, there are
numerous pages that return your visible IP Address. Sometimes they
are operational, somethines not. Sometimes they route you to another
page where tihe IP Address is stored differently. Makes it pretty
unreliable and messy.