Get IP Address

This forum is meant for questions and discussions about the X# language and tools
Karl-Heinz
Posts: 774
Joined: Wed May 17, 2017 8:50 am
Location: Germany

Get IP Address

Post by Karl-Heinz »

seems your platform setting is != "x86"

regards
Karl-Heinz
User avatar
Fabrice
Posts: 459
Joined: Thu Oct 08, 2015 7:47 am
Location: France

Get IP Address

Post 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
XSharp Development Team
fabrice(at)xsharp.eu
FFF
Posts: 1580
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

Get IP Address

Post by FFF »

Karl-Heinz,
<argh> - one click and all running fine...
Thx
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
Post Reply