get ip?

Blitz3D Forums/Blitz3D Beginners Area/get ip?

RXArt(Posted 2004) [#1]
hi all again! I've just got my parser done. I'm now experimenting with networks. However, I can't seem to find a command that help returns the ip address (if available) of the user's computer. Is it possible, or did I missed something? Thanks again!


Agamer(Posted 2004) [#2]
yeh it is possible


GfK(Posted 2004) [#3]
yeh it is possible
Very helpful. :/

RXArt - this code is taken from the blitz documentation for the HostIP command:
; First call CountHostIPs (blank infers the local machine) 
n = CountHostIPs("") 
; n now contains the total number of known host machines. 

; Obtain the internal id for the IP address 
ip = HostIP(1) 

; Convert it to human readable IP address 
ipaddress$ = DottedIP$(ip) 

Print "Dotted IP Test" 
Print "==============" 
Print "" 
Print "Internal Host IP ID:" + ip 
Print "Dotted IP Address:" + ipaddress$ 
Print "" 
Print "Press any key to continue" 

WaitKey() 

End 



RXArt(Posted 2004) [#4]
thanks. I was looking at http://blitzbasic.com/codearcs/codearcs.php?code=139, and it was pretty scary. But thanks for the shorter version, agamer and gfk!


RXArt(Posted 2004) [#5]
Just to ask, how do I find out more about counthostips and hostip? I'm still trying to understand them, and I'm having a hard time understanding the documentation. for example, why hostip(1)? or why I get memorcy access violation if I don't include counthostips. thanks


Stoop Solo(Posted 2004) [#6]
There is a command to get the IP address of every network adapter of a specified host computer. If you specify no host name, it will report the host adapter info of the computer running the program. CountHostIPs is the command for retrieving the adapter info, which returns the number of host adapters present. Each adapter's IP can then be accessed using HostIP(n).

hadapters = CountHostIPs("")
Dim ips(hadapters)

For x = 1 To hadapters
	ips(x) = HostIP(x)
	Print "Adapter "+x+" IP is "+DottedIP$(ips(x))
Next

WaitKey()


This routine will evaluate all host adapters on the computer running it and store them in an array, giving you:

hadapters - number of network adapters on the computer
ips(n) - IP address, in integer form, of network adapter n.

Note that in the instance there is no adapter, CountHostIPs will report back one adapter, and it's IP will be 2130706433 (127.0.0.1), the internal loopback IP. If your first IP is reported as that, you can make the assumption the machine running the program has no network connection.

To determine another computer's IP from yours, you will need to know the host name of the other computer, and change CountHostIPs("") to CountHostIPs("othercomp"), where othercomp is the host name of the, er, other comp. Then the routine will return the IP of every adapter available to your computer from the other (which may not necessarily be every adapter on the other computer).

If the host name of the other computer is unknown, you'll have to get the other computer to send you a packet, then you can retreive the source IP of the received packet.


Stoop Solo(Posted 2004) [#7]
Gah, I was too slow. Oh well, hopefully there's enough there about the workings of CountHostIPs for you. I've been on something of a BLitz UDP learning binge myself.


RXArt(Posted 2004) [#8]
thank you very much, stoop solo! Actually, I've got blitz3d quite a year ago, but I hardly came up with anything, except for demos,cuz I's having a hard time in college. Now I'm starting to go through every one of the commands, starting from basic string manipulations, to 2d, 3d, and finally, those peek thingys. thank you everyone!!