Get the native Nic MAC address code
</summary>
<returns></returns>
<summary>
public string Getnetworkadpaterid ()
{
Try
{
String mac = "";
System.Management.ManagementClass mc = new System.Management.ManagementClass ("Win32_NetworkAdapterConfiguration");
System.Management.ManagementObjectCollection MOC = MC. GetInstances ();
foreach (System.Management.ManagementObject mo in MOC)
if ((bool) mo["ipenabled"] = = True)
{
Mac + = mo["MacAddress"]. ToString () + "";
Break
}
MOC = null;
MC = null;
Return Mac. Trim ();
}
catch (Exception e)
{
return "Umnik";
}
}
Method of obtaining MAC address based on IP address
Here's a way to get a remote MAC address
[DllImport ("Iphlpapi.dll")]
static extern int Sendarp (Int32 destip, Int32 Srcip, ref Int64 MACADDR, ref Int32 Phyaddrlen);
[DllImport ("Ws2_32.dll")]
static extern Int32 inet_addr (string ipaddr);
<summary>
Sendarp Get MAC Address
</summary>
<param name= "REMOTEIP" > Target machine IP address (192.168.1.1) </param>
<returns> MAC address of Target machine </returns>
public static string Getmacaddr_remote (String remoteip)
{
StringBuilder macAddress = new StringBuilder ();
Try
{
Int32 remote = inet_addr (REMOTEIP);
Int64 macinfo = new Int64 ();
Int32 length = 6;
Sendarp (remote, 0, ref macinfo, ref length);
String temp = convert.tostring (Macinfo, 16). PadLeft (12, ' 0 '). ToUpper ();
int x = 12;
for (int i = 0; i < 6; i++)
{
if (i = = 5)
{
Macaddress.append (temp. Substring (X-2, 2));
}
Else
{
Macaddress.append (temp. Substring (X-2, 2) + "-");
}
X-= 2;
}
return macaddress.tostring ();
}
Catch
{
return macaddress.tostring ();
}
}
Get an IP address that penetrates the proxy
Get IP Address
String user_ip = "";
if (request.servervariables["Http_via"]! = NULL)//If there is an agent then take the value directly over the proxy
{
User_ip = request.servervariables["Http_x_forwarded_for"]. ToString ();
}
Else
{
User_ip = request.servervariables["REMOTE_ADDR"]. ToString ();
}
C # Gets the MAC address native or remote