-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHelperMethods.cs
44 lines (43 loc) · 1.28 KB
/
HelperMethods.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.NetworkInformation;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
namespace EasyService {
public class HelperMethods {
static public string GetMacAddress() {
string macAddresses = "";
foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces()) {
if (nic.OperationalStatus == OperationalStatus.Up) {
macAddresses += nic.GetPhysicalAddress().ToString();
break;
}
}
return macAddresses;
}
static public string GetBeautiMacAddress() {
string macAddresses = GetMacAddress();
if (macAddresses.Length != 12) {
return macAddresses = "Error";
}
macAddresses = macAddresses.Insert(2, ":");
macAddresses = macAddresses.Insert(5, ":");
macAddresses = macAddresses.Insert(8, ":");
macAddresses = macAddresses.Insert(11, ":");
macAddresses = macAddresses.Insert(14, ":");
return macAddresses;
}
static public string GetIPv4() {
IPHostEntry host = Dns.GetHostEntry(Dns.GetHostName());
foreach (IPAddress ip in host.AddressList) {
if (ip.AddressFamily == AddressFamily.InterNetwork) {
return ip.ToString();
}
}
return null;
}
}
}