Downloads:
Features:
- Show all connected devices to your network
- Get devices MAC address info (Host name, Manufacturer, etc.. )
Note:
- This program gets MAC info from ( https://macvendors.com/ )
C# Source Code:
- Main.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 |
using System; using System.Windows.Forms; using System.Diagnostics; using System.Management; using System.Net; using System.Net.NetworkInformation; using System.Threading; using System.Runtime.InteropServices; using System.Text.RegularExpressions; using System.Net.Http; using System.Net.Sockets; using Newtonsoft.Json; namespace Network_Watcher { public partial class Main : Form { #region Network Tools [DllImport("wininet.dll")] // Connection Status private extern static bool InternetGetConnectedState(out int Description, int ReservedValue); // Connection Status System.Windows.Forms.Timer t = new System.Windows.Forms.Timer(); Thread myThread = null; // IP Checking public string IP; // For MAC Address public string IP2; // For MAC Address in Router Connections public string Di = ""; public string mn = ""; #endregion public Main() { InitializeComponent(); } private void Main_Load(object sender, EventArgs e) { } #region Router Connections #region voids public void scan(string subnet) { Ping myPing; PingReply reply; IPAddress addr; IPHostEntry host; progressBar.Maximum = 255; progressBar.Value = 0; listView1.Items.Clear(); for (int i = 1; i <= 255; i++) // 255 { try { string subnetn = "." + i.ToString(); myPing = new Ping(); reply = myPing.Send(subnet + subnetn, 900); txtScanIp.Text = "Scanning : " + subnet + subnetn; if (reply.Status == IPStatus.Success) { try { addr = IPAddress.Parse(subnet + subnetn); host = Dns.GetHostEntry(addr); IP2 = Convert.ToString(addr); #region 192.168.1.1 & Clients try { if (subnet + subnetn == "192.168.1.1") { Di = "Router"; } } catch { Di = ""; } if (Di == "") { Di = "Client"; } #endregion #region Manufacturer if (radioButtonSpeed.Checked == true) { mn = ""; } if (radioButtonSlow.Checked == true) { int Desc; /// Connection Status if (InternetGetConnectedState(out Desc, 0) == true) { try { WebClient client = new WebClient(); mn = client.DownloadString("http://api.macvendors.com/" + GetMacAddress(subnet + subnetn)); } catch { mn = ""; } } else { mn = "No Internet !"; } } #endregion listView1.Items.Add(new ListViewItem(new String[] { subnet + subnetn, host.HostName, GetMacAddress(subnet + subnetn), "Up", Di, mn })); Di = ""; } catch { } } progressBar.Value += 1; } catch { } } int count = listView1.Items.Count; txtLocalIp.Enabled = true; txtLocalIp.Show(); btnScan.Enabled = true; btnStop.Enabled = false; progressBar.Hide(); txtScanIp.Text = "Finished !"; txtCounter.Text = "Scanning Done ! Found : " + count.ToString() + " Hosts."; groupBox6.Enabled = true; myThread.Abort(); } public void query(string host) { string temp = null; string[] _searchClass = { "Win32_ComputerSystem", "Win32_OperatingSystem", "Win32_BaseBoard", "Win32_BIOS" }; string[] param = { "UserName", "Caption", "Product", "Description" }; for (int i = 0; i <= _searchClass.Length - 1; i++) { txtScanIp.Text = "Getting information ..."; try { ManagementObjectSearcher searcher = new ManagementObjectSearcher("\\\\" + host + "\\root\\CIMV2", "SELECT *FROM " + _searchClass[i]); foreach (ManagementObject obj in searcher.Get()) { txtScanIp.Text = "Getting information ..."; temp += obj.GetPropertyValue(param[i]).ToString() + "\n"; if (i == _searchClass.Length - 1) { txtScanIp.Text = "Done !"; MessageBox.Show(temp, "Hostinfo : " + host, MessageBoxButtons.OK, MessageBoxIcon.Information); break; } txtScanIp.Text = "Getting information ..."; } } catch { MessageBox.Show("Cannot retrieve host info for security reasons !", "Hostinfo : " + host, MessageBoxButtons.OK, MessageBoxIcon.Information); break; } } } #endregion // Search private void btnScan_Click(object sender, EventArgs e) { progressBar.Show(); if (txtLocalIp.Text == string.Empty) { MessageBox.Show("No IP address entered !", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { txtLocalIp.Hide(); btnScan.Enabled = false; myThread = new Thread(() => scan(txtLocalIp.Text)); myThread.Start(); if (myThread.IsAlive == true) { btnStop.Enabled = true; txtLocalIp.Enabled = false; groupBox6.Enabled = false; } } } // Stop private void btnStop_Click(object sender, EventArgs e) { try { myThread.Abort(); btnScan.Enabled = true; btnStop.Enabled = false; txtLocalIp.Show(); txtLocalIp.Enabled = true; groupBox6.Enabled = true; progressBar.Hide(); txtCounter.Text = "Stoped !!!"; } catch { } } // List View private void listView1_MouseClick(object sender, MouseEventArgs e) { ListView listView = sender as ListView; if (e.Button == System.Windows.Forms.MouseButtons.Right) { ListViewItem item = listView.GetItemAt(e.X, e.Y); if (item != null) { item.Selected = true; contextMenuStrip1.Show(listView, e.Location); } } } // Tool Strip Menu private async void showMacInfoToolStripMenuItem_Click(object sender, EventArgs e) { int Desc; /// Connection Status if (InternetGetConnectedState(out Desc, 0) == true) { try { string mac = listView1.SelectedItems[0].SubItems[2].Text.ToString(); HttpClient client = new HttpClient(); string url = "http://macvendors.co/api/" + mac; var response = await client.GetAsync(string.Format(url)); string result = await response.Content.ReadAsStringAsync(); MACinfo.RootObject root = JsonConvert.DeserializeObject<MACinfo.RootObject>(result); string info = "Countyr : " + root.result.country + "\nCompany : " + root.result.company + "\nAddress : " + root.result.address + "\nMac Prefix : " + root.result.mac_prefix + "\nStart Hex : " + root.result.start_hex + "\nEnd Hex : " + root.result.end_hex + "\nType : " + root.result.type; MessageBox.Show(info, "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch { MessageBox.Show("Server Error !", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { MessageBox.Show("Require Internet connection !", "Attention", MessageBoxButtons.OK, MessageBoxIcon.Information); } } #endregion #region Get MAC Address & External IP public string getExternalIp() { try { string externalIP; externalIP = (new WebClient()).DownloadString("http://ipinfo.io/"); externalIP = (new Regex(@"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}")) .Matches(externalIP)[0].ToString(); return externalIP; } catch { return null; } } public string GetMacAddress() { foreach (NetworkInterface NetI in NetworkInterface.GetAllNetworkInterfaces()) { if (NetI.NetworkInterfaceType == NetworkInterfaceType.Wireless80211 || NetI.NetworkInterfaceType == NetworkInterfaceType.Ethernet && NetI.OperationalStatus == OperationalStatus.Up) { bool found = false; foreach (UnicastIPAddressInformation UniIpAddrInfo in NetI.GetIPProperties().UnicastAddresses) { if (UniIpAddrInfo.Address.AddressFamily != AddressFamily.InterNetwork || UniIpAddrInfo.AddressPreferredLifetime == UInt32.MaxValue) continue; found = (UniIpAddrInfo.Address.ToString() == IP); } if (found) { string macAddr = NetI.GetPhysicalAddress().ToString(); return (macAddr.Length != 12) ? "00:00:00:00:00:00" : Regex.Replace(macAddr, "(.{2})(.{2})(.{2})(.{2})(.{2})(.{2})", "$1:$2:$3:$4:$5:$6"); } } } return "Unknown"; } public string GetMacAddress2() { foreach (NetworkInterface NetI in NetworkInterface.GetAllNetworkInterfaces()) { if (NetI.NetworkInterfaceType == NetworkInterfaceType.Wireless80211 || NetI.NetworkInterfaceType == NetworkInterfaceType.Ethernet && NetI.OperationalStatus == OperationalStatus.Up) { bool found = false; foreach (UnicastIPAddressInformation UniIpAddrInfo in NetI.GetIPProperties().UnicastAddresses) { if (UniIpAddrInfo.Address.AddressFamily != AddressFamily.InterNetwork || UniIpAddrInfo.AddressPreferredLifetime == UInt32.MaxValue) continue; found = (UniIpAddrInfo.Address.ToString() == IP2); } if (found) { string macAddr = NetI.GetPhysicalAddress().ToString(); return (macAddr.Length != 12) ? "00:00:00:00:00:00" : Regex.Replace(macAddr, "(.{2})(.{2})(.{2})(.{2})(.{2})(.{2})", "$1:$2:$3:$4:$5:$6"); } } } return "Unknown"; } public string GetMacAddress(string ipAddress) // For Clients { string macAddress = string.Empty; System.Diagnostics.Process Process = new System.Diagnostics.Process(); Process.StartInfo.FileName = "arp"; Process.StartInfo.Arguments = "-a " + ipAddress; Process.StartInfo.UseShellExecute = false; Process.StartInfo.RedirectStandardOutput = true; Process.StartInfo.CreateNoWindow = true; Process.Start(); string strOutput = Process.StandardOutput.ReadToEnd(); string[] substrings = strOutput.Split('-'); if (substrings.Length >= 8) { macAddress = substrings[3].Substring(Math.Max(0, substrings[3].Length - 2)) + substrings[4] + substrings[5] + substrings[6] + substrings[7] + substrings[8].Substring(0, 2); string macAddr = macAddress.ToString(); return (macAddr.Length != 12) ? "00:00:00:00:00:00" : Regex.Replace(macAddr, "(.{2})(.{2})(.{2})(.{2})(.{2})(.{2})", "$1:$2:$3:$4:$5:$6").ToUpper(); // ToUpper() / To make mac address in capital letters return macAddr; } else { Di = "This Computer"; return GetMacAddress2(); } } #endregion } } |
- MACinfo.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Network_Watcher { class MACinfo { public class Result { public string company { get; set; } public string mac_prefix { get; set; } public string address { get; set; } public string start_hex { get; set; } public string end_hex { get; set; } public string country { get; set; } public string type { get; set; } public string error { get; set; } } public class RootObject { public Result result { get; set; } } } } |
Screenshots:
NuGet Packages:
- Newtonsoft.json
Unsupported devices:
- Netgear wifi extender n300, etc…
Similar Apps:
Contact: