Repository navigation
Expand file tree
/
Copy pathIPHelper.cs
More file actions
executable file
·79 lines (77 loc) · 2.65 KB
/
Copy pathIPHelper.cs
File metadata and controls
executable file
·79 lines (77 loc) · 2.65 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
using System.Net.NetworkInformation;
using System.Management;
namespace RemoteControl.Net
{
public class IPHelper
{
public static string GetRealIP()
{
using (var webClient = new WebClient())
{
try
{
var temp = webClient.DownloadString("http://iframe.ip138.com/ic.asp");
var ip = Regex.Match(temp, @"\[(?<ip>\d+\.\d+\.\d+\.\d+)]").Groups["ip"].Value;
return !string.IsNullOrEmpty(ip) ? ip : null;
}
catch
{
return string.Empty;
}
}
}
public static string GetWirelessNetworkMac()
{
string strMAC = "";
NetworkInterface[] fNetworkInterfaces = NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface adapter in fNetworkInterfaces)
{
strMAC = adapter.GetPhysicalAddress().ToString();
if (!adapter.Description.Contains("PCI") && adapter.Description.Contains("Wireless"))
return strMAC;
}
return null;
}
public static string GetWirelessNetworkIP()
{
try
{
string wlmac = GetWirelessNetworkMac();
string mac = "";
string st = "";
ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
if ((bool)mo["IPEnabled"] == true)
{
mac = mo["MacAddress"].ToString();
System.Array ar;
ar = (System.Array)(mo.Properties["IpAddress"].Value);
for (int i = 0; i < ar.GetLength(0); i++)
{
st = ar.GetValue(i).ToString();
if (mac.Replace(":","") == wlmac)
{
return st;
}
}
}
}
moc = null;
mc = null;
return null;
}catch
{
return null;
}
}
}
}