Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Presumes IPV6 is enabled on the network adaptor. Crashes if not #2

Open
robvon opened this issue Nov 5, 2016 · 0 comments
Open

Presumes IPV6 is enabled on the network adaptor. Crashes if not #2

robvon opened this issue Nov 5, 2016 · 0 comments

Comments

@robvon
Copy link

robvon commented Nov 5, 2016

public static ArrayList get_ips()
{
var datasets = new ArrayList();

		var scope = new ManagementScope(Functions.GetServerName());
		var query = new SelectQuery("Select Caption, IPAddress, MACAddress From Win32_NetworkAdapterConfiguration WHERE IPEnabled = 'TRUE'");
		var searcher = new ManagementObjectSearcher(scope, query);
		var count = 0; //-> fake adapter name

		foreach (var x in searcher.Get())
		{

			var dataset = new ArrayList();
			var ips = (string[])x["IPAddress"];

			dataset.Add("eth" + count);   //x["Caption"]
			dataset.Add(ips[0]);          //-> IP v4
			dataset.Add(ips.Length > 1 ? ips[1] : "N/A");  <<<<< ----- -THis works better
			dataset.Add(x["MACAddress"]); //-> Mac address
			datasets.Add(dataset);
			count++;
		}

		return datasets;
	}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant