Notifications
Clear all
[Closed] Connected Local IP
Jul 28, 2015 1:59 pm
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
Jul 28, 2015 1:59 pm
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
)
1 Reply
because i just wanted to know how it makes the string i knew it’s four bytes but i didn’t know the order