Notifications
Clear all

[Closed] Connected Local IP

I’ve found a way to do this:

(	
 	cc=(dotnetclass "System.Net.Dns")
 	oo =cc.GetHostAddresses(cc.GetHostName())
 	oo[2].tostring() 
 )

It’s working well at me, but tell me, is there a better way of doing this?

4 Replies

all is almost right. but if you want to be absolutely correct:

fn getLocalIPAddress asString:on =
(
	dns = dotnetclass "System.Net.Dns"
	entry = dns.GetHostEntry (dns.GetHostName())
	for address in entry.Addresslist where address.AddressFamily == address.AddressFamily.InterNetwork do
	(
		exit with (if asString then address.ToString() else address.Address)
	)
)

and BONUS

fn intIPAddressToString ip = 
(
	str = ""
	for k=0 to 3 do 
	(
		str += formattedprint (bit.and ip 0xFF) format:"d"
		if k < 3 do 
		(
			ip = bit.shift ip -8
			str += "."
		)
	)
	str
) 
 lo1

Why not

(dotnetObject "System.Net.IPAddress" ip).ToString()
1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

because i just wanted to know how it makes the string i knew it’s four bytes but i didn’t know the order

Thank you, Denis!