d

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Web; using System.Text;
using System.Runtime.InteropServices; /// <summary>
///NetHelper 的摘要说明
/// </summary>
public class NetHelper
{
public NetHelper()
{ } public static string GetBrowserType()
{
return HttpContext.Current.Request.Browser.Type;
} public static string GetSysVersion()
{
string Agent = HttpContext.Current.Request.ServerVariables["HTTP_USER_AGENT"]; if (Agent.IndexOf("NT 4.0") > )
{
return "Windows NT ";
}
else if (Agent.IndexOf("NT 5.0") > )
{
return "Windows 2000";
}
else if (Agent.IndexOf("NT 5.1") > )
{
return "Windows XP";
}
else if (Agent.IndexOf("NT 5.2") > )
{
return "Windows 2003";
}
else if (Agent.IndexOf("NT 6.0") > )
{
return "Windows Vista";
}
else if (Agent.IndexOf("WindowsCE") > )
{
return "Windows CE";
}
else if (Agent.IndexOf("NT") > )
{
return "Windows NT ";
}
else if (Agent.IndexOf("9x") > )
{
return "Windows ME";
}
else if (Agent.IndexOf("") > )
{
return "Windows 98";
}
else if (Agent.IndexOf("") > )
{
return "Windows 95";
}
else if (Agent.IndexOf("Win32") > )
{
return "Win32";
}
else if (Agent.IndexOf("Linux") > )
{
return "Linux";
}
else if (Agent.IndexOf("SunOS") > )
{
return "SunOS";
}
else if (Agent.IndexOf("Mac") > )
{
return "Mac";
}
else if (Agent.IndexOf("Linux") > )
{
return "Linux";
}
else if (Agent.IndexOf("Windows") > )
{
return "Windows";
}
return "unknow"; } /// <summary>
/// 如果有代理那么越过代理直接取值
/// </summary>
/// <returns></returns>
public static string GetClientIp()
{
if (HttpContext.Current.Request.ServerVariables["HTTP_VIA"] != null)
return HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
else
return HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"].ToString();
} public static string GetHostName(string ipStr)
{ string hostName = string.Empty;
try
{
System.Net.IPAddress ip = System.Net.IPAddress.Parse(ipStr);
System.Net.IPHostEntry host = System.Net.Dns.GetHostEntry(ip);
hostName = host.HostName;
}
catch
{ }
return hostName;
} [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获取MAC地址
/// </summary>
/// <param name="RemoteIP">目标机器的IP地址如(192.168.1.1)</param>
/// <returns>目标机器的mac 地址</returns>
public static string getMacAddr_Remote(string RemoteIP)
{
StringBuilder macAddress = new StringBuilder();
try
{
Int32 remote = inet_addr(RemoteIP);
Int64 macInfo = new Int64();
Int32 length = ;
SendARP(remote, , ref macInfo, ref length);
string temp = Convert.ToString(macInfo, ).PadLeft(, '').ToUpper();
int x = ;
for (int i = ; i < ; i++)
{
if (i == )
{
macAddress.Append(temp.Substring(x - , ));
}
else
{
macAddress.Append(temp.Substring(x - , ) + "-");
}
x -= ;
}
return macAddress.ToString();
}
catch
{
return macAddress.ToString();
}
}
}

程序员的基础教程:菜鸟程序员

最新文章

  1. 启动tomcat 报 Could not delete D:/online/.metadata/.plugins/org.eclipse.wst.server.core/tm
  2. [Unity3D插件]2dToolKit系列三 碰撞检测功能的实现以及障碍物的随机摆放
  3. Ubuntu 14.10 创建虚拟网卡实现桥接网络
  4. Git学习笔记(一)
  5. [ZigBee] 9、ZigBee之AD剖析——AD采集CC2530温度串口显示
  6. 性能测试一般过程与LR性能测试过程
  7. Java 读取文件到字符串
  8. MUA
  9. Jquery获得下拉框的值
  10. Spark目录
  11. php and web service with wsdl
  12. 浅谈Oracle数据库性能优化的目标
  13. 页面json 格式化+颜色高亮
  14. MapReduce执行过程
  15. Java基础知识(一)
  16. 异常-----spring明明注入了Service到Action中,为什么运行的时候Service为空,在抽象类中,有子类来继承的
  17. PowerDesigner 批量添加字段
  18. Jmeter_24个常用函数
  19. 关于 Nginx 配置 WebSocket 400 问题
  20. MYSQL两个数据库字符集保持一致问题

热门文章

  1. [转载] FFMPEG之AVRational TimeBase成员理解
  2. 剑指Offer面试题:8.二进制中1的个数
  3. 重温CLR(六)方法和参数
  4. PHP 操作XML文档
  5. 洛谷 1099 ( bzoj 1999 ) [Noip2007]Core树网的核
  6. 不用jq的异步数据获取
  7. Go基本语句
  8. 蓝桥杯 算法训练 ALGO-15 旅行家的预算
  9. oracle查询题目2道
  10. PL/SQL 训练02--集合数组