xsharp.eu • Get IP Address - Page 2
Page 2 of 2

Get IP Address

Posted: Sun Nov 07, 2021 11:16 am
by Karl-Heinz
seems your platform setting is != "x86"

regards
Karl-Heinz

Get IP Address

Posted: Sun Nov 07, 2021 11:36 am
by Fabrice
Hi Joe,

May I suggest a more complex solution ;)

Try this :

Code: Select all

using System.Net.NetworkInformation
USING System.Net.Sockets

PUBLIC CLASS NetworkTools
	PUBLIC STATIC METHOD GetAllIPv4(netType AS NetworkInterfaceType ) AS List<STRING>
		RETURN (;
			FROM x IN ;
			(;
			FROM x IN NetworkInterface.GetAllNetworkInterfaces();
				WHERE (x:NetworkInterfaceType == netType) .AND. (x:OperationalStatus == OperationalStatus.Up);
				SELECT x;
			);
			:SelectMany({x AS NetworkInterface => x:GetIPProperties():UnicastAddresses});
				WHERE x:Address:AddressFamily == AddressFamily.InterNetwork;
				SELECT x:Address:ToString();
			):ToList()


	PUBLIC STATIC METHOD GetAllLocalIPv4() AS List<STRING>
		LOCAL allLocalIPv AS List<STRING>
		// Wired
		allLocalIPv := GetAllIPv4(NetworkInterfaceType.Ethernet)
		// Wifi
		allLocalIPv:AddRange(GetAllIPv4(NetworkInterfaceType.Wireless80211))
		RETURN allLocalIPv


END CLASS
Calling it with

Code: Select all

VAR IPs := NetworkTools.GetAllLocalIPv4()
FOREACH VAR ip IN IPs
 ? ip
NEXT
Regards,
Fab

Get IP Address

Posted: Sun Nov 07, 2021 12:19 pm
by FFF
Karl-Heinz,
<argh> - one click and all running fine...
Thx