Get Client IP:
private String Getclientip ()
{
string result = httpcontext.current.request.servervariables["http_x_forwarded_for"];
if (Null = result | | = result = String.Empty)
{
result = httpcontext.current.request.servervariables["REMOTE_ADDR"];
}
if (Null = result | | = result = String.Empty)
{
result = HttpContext.Current.Request.UserHostAddress;
}
return result;
}
Get MAC Address:
[DllImport ("Iphlpapi.dll")]
private static extern int Sendarp (Int32 dest,int32 host,ref Int64 mac,ref length);
[DllImport ("Ws2_32.dll")]
private static extern Int32 inet_addr (string IP);
private void Page_Load (object sender, System.EventArgs e)
{
Place user code here to initialize page
Try
{
String userip=request.userhostaddress;
String strclientip = Request.UserHostAddress.ToString (). Trim ();
Int32 ldest = inet_addr (Strclientip); IP of destination
Int32 lhost = inet_addr (""); IP for local server
Int64 macinfo = new Int64 ();
Int32 len = 6;
int res = Sendarp (ldest,0, ref macinfo, ref Len);
String Mac_src=macinfo. ToString ("X");
if (mac_src = = "0")
{
if (userip== "127.0.0.1")
Response.Write ("Visiting localhost!");
Else
Response.Write ("Welcome" from IP for "+ Userip +" friends.) "+" <br> ");
Return
}
while (MAC_SRC. LENGTH<12)
{
MAC_SRC = mac_src. Insert (0, "0");
}
String Mac_dest= "";
for (int i=0;i<11;i++)
{
if (0 = = (i% 2))
{
if (i = = 10)
{
Mac_dest = Mac_dest. Insert (0,MAC_SRC. Substring (i,2));
}
Else
{
Mac_dest = "-" + mac_dest. Insert (0,MAC_SRC. Substring (i,2));
}
}
}
Response.Write ("Welcome" from IP for "+userip+" <br> "+", MAC address for "+mac_dest+" friend. "
+ "<br>");
}
catch (Exception err)
{
response.write (err . message);
}
}