private void btnThisMacOnline_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtMacToCheck.Text)) { MessageBox.Show("MAC to check can't be empty", "Empty MAC"); return; } MACHandler macHandler = new MACHandler(); try { if (macHandler.IsOnline(MACHandler.ConvertToOnlyNumberMac(txtMacToCheck.Text))) { MessageBox.Show("The PC of this MAC is online now", "Online", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show("The PC of this MAC is offline now", "Offline", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } catch (ArgumentNullException ex) { MessageBox.Show($"{ex.Message}\n" + $"Error: {ex.InnerException.Message}", "This MAC Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception ex) { MessageBox.Show($"Error when ping: {ex.Message}", "Ping Error"); } }
private bool SetNewMac(string newMac) { string newMacWithoutSeparator = MACHandler.ConvertToOnlyNumberMac(newMac); RegistryKey rKey = null; try { rKey = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}\0002", true); rKey.SetValue("NetworkAddress", newMacWithoutSeparator); rKey.Close(); return(true); } catch (Exception ex) { MessageBox.Show(ex.Message); return(false); } finally { rKey.Close(); } }