I've tried using:
Code: Select all
ExamineIPAddresses()
ValidateIP$ = IPString(NextIPAddress())
MessageRequester("",ValidateIP$)
Code: Select all
ExamineIPAddresses()
ValidateIP$ = IPString(NextIPAddress())
MessageRequester("",ValidateIP$)
Code: Select all
InitNetwork()
Debug StringField(GetHTTPHeader("http://h3x0r.ath.cx/Sonstiges/ShowMyIp12.php"), 2, Chr(34))
Oh, so we'll have to always locate the internet IP from outside of PureBasic?ts-soft wrote:There can't a native function for this!
Code: Select all
#PUBLIC_IP=1
#LOCALE_IP=2
#DATA_BUFFER_LENGHT=256
Declare.s GetIPAddress(IP_Type)
InitNetwork()
Procedure.s GetIPAddress(IP_Type)
Protected i=0, l
Protected *BUFFER_connection, *p
Protected tmp$=""
Select IP_Type
Case #PUBLIC_IP
*BUFFER_connection=AllocateMemory(#DATA_BUFFER_LENGHT)
If *BUFFER_connection
l=OpenNetworkConnection("www.indirizzo-ip.com",80)
If l
tmp$="GET /ip.php?.txt HTTP/1.1"+#CRLF$
tmp$+"Host: www.indirizzo-ip.com"+#CRLF$
tmp$+"Connection: Close"+#CRLF$+#LF$
SendNetworkString(l,tmp$)
Repeat
i=NetworkClientEvent(l)
Until i<>0
If i=#PB_NetworkEvent_Data
i=ReceiveNetworkData(l,*BUFFER_connection,#DATA_BUFFER_LENGHT)
EndIf
CloseNetworkConnection(l)
tmp$=""
If i<>-1
If PeekS(*BUFFER_connection,15,#PB_Ascii)="HTTP/1.1 200 OK"
*p=*BUFFER_connection+213
Repeat
*p+1
i=PeekB(*p)
If i<>10
tmp$+Chr(i)
Else
Break
EndIf
ForEver
EndIf
EndIf
EndIf
FreeMemory(*BUFFER_connection)
EndIf
Case #LOCALE_IP
If ExamineIPAddresses()
Repeat
l=NextIPAddress()
If l
If i>0
; If tmp$
tmp$+","
EndIf
tmp$+IPString(l)
i+1
EndIf
Until l=0
EndIf
EndSelect
ProcedureReturn(tmp$)
EndProcedure
; Esempio
;IP$=GetIPAddress(#LOCALE_IP)
;Debug IP$
;Debug Len(IP$)
;IP$=GetIPAddress(#PUBLIC_IP)
;Debug IP$
;Debug Len(IP$)
Code: Select all
If InitNetwork()
Hostname$ = Space(255)
gethostname_(Hostname$,255)
Debug "Hostname: "+Hostname$
pHostinfo = gethostbyname_(Hostname$)
If pHostinfo = 0
Debug "Unable to resolve domain name."
Else
CopyMemory (pHostinfo, hostinfo.HOSTENT, SizeOf(HOSTENT))
If hostinfo\h_addrtype <> #AF_INET
Debug "A non-IP address was returned."
Else
While PeekL(hostinfo\h_addr_list+AdressNumber*4)
ipAddress = PeekL(hostinfo\h_addr_list+AdressNumber*4)
Debug StrU(PeekB(ipAddress),0)+"."+StrU(PeekB(ipAddress+1),0)+"."+StrU(PeekB(ipAddress+2),0)+"."+StrU(PeekB(ipAddress+3),0)
AdressNumber+1
Wend
EndIf
EndIf
Else
Debug "Network can't be initialized"
EndIf
Hi SFSxOI,SFSxOI wrote:Something I saved from someone here in the forum - credit to the original poster. No external sites needed.
Code: Select all
OpenConsole()
PrintN(GetEnvironmentVariable("REMOTE_ADDRESS")) ; The IP address of the visitor
CloseConsole()