On the Amiga and Windows the first line of code below works fine but I had to add some workarounds to get the right IP on Linux.
Code: Select all
Function p_GetIP() Local myip = ToIP(GetHostName()) /* OK on Amiga and Win, usually returns 127.0.0.1 on Linux */ /* Workaround for Linux that requires external connection */ If StartsWith(myip,"127") Or StartsWith(myip,"0.") Local id = OpenConnection(Nil, "220.127.116.11", 53) myip = GetLocalIP(id) CloseConnection(id) /* Workaround with manual user input */ If StartsWith(myip,"127") Or StartsWith(myip,"0.") Local ip,ok = StringRequest("GetIP", "Could not find local network IP\nPlease specify your current LAN IP (IPv4)") If ip And ok Then myip = ip EndIf EndIf Return(myip) EndFunction
I'm just not sure how the network library could be improved to return the LAN IP instead of the loopback address. Maybe some NoLoopoback=True tag?
And there's also the situation where a machine has multiple network interfaces, wired and or wireless, if more than one is up, how to at least get a list to let the user pick one?