GET IP of local System

Share your advanced PureBasic knowledge/code with the community.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

GET IP of local System

Post by BackupUser »

Restored from previous forum. Originally posted by tranquil.

Here is the source again if you want to find out IP(s) of your Host. (Just for complimentation in Tip's & Tricks again) :)

Have Fun.

Code: Select all

;---------------------------
; GET IP Example
;
;NetWork References...
;
;http://www.vbip.com/winsock-api/gethostname/gethostname-01.asp -> How To get name And IP address of the local system
;http://www.vbapi.com/ref/h/hostent.html -> HOSTENT Structure
;
;If you need all IPs of your system, its much as easy, please call us if you have problems.
;
;Tranquilizer & Mr.Vain of Secretly!
;---------------------------


a=initnetwork()
*buffer = GlobalAlloc_(#GMEM_FIXED | #GMEM_ZEROINIT, 2048)

Procedure.l calc(va.b)
If va.b<=0
res.l=256+va.b
Else
res.l=va.b
EndIf
ProcedureReturn res.l
EndProcedure


a=gethostname_(*buffer,2048)

adr.l=gethostbyname_(*buffer)

h_name.l=peekl(adr.l) ;Point to host name
h_array.l=peekl(adr.l+4) ; Pointer to an Array -- NOT REQUIRED YET
h_addrtype=peekl(adr.l+8) ; Addr type Integer -- NOT REQUIRED YET
h_length=peekl(adr.l+12) ;Length as integer -- NOT REQUIRED YET
h_addr_list=peekl(adr.l+16) ; List of Addresses (IPs)

ipadr.l=h_addr_list

ipb1.b=peekb(ipadr.l)
ip1.l=calc(ipb1.b)

ipb2.b=peekb(ipadr.l+1)
ip2.l=calc(ipb2.b)

ipb3.b=peekb(ipadr.l+2)
ip3.l=calc(ipb3.b)

ipb4.b=peekb(ipadr.l+3)
ip4.l=calc(ipb4.b)

messagerequester("Host:"+peeks(h_name.l),"Your first IP:"+str(ip1.l)+"."+str(ip2.l)+"."+str(ip3.l)+"."+str(ip4.l),0)

End


Tranquilizer/ Secretly!