
1个回答
2013-04-29
展开全部
/// <summary>
/// 获取IP
/// </summary>
/// <returns></returns>
public static string GetClientIP()
{
string clientIP = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (string.IsNullOrEmpty(clientIP))
{
clientIP = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
}
if (string.IsNullOrEmpty(clientIP))
{
clientIP = HttpContext.Current.Request.UserHostAddress;
}
return clientIP;
}
//再送你个获取XP MAC的
public static string GetMac()
{
string mac = "";
int length = 0;
System.Diagnostics.Process process = new System.Diagnostics.Process();//线程类,可以启动关闭一些线程
process.StartInfo.FileName = "nbtstat";//传递启动线程名,命令为nbtstat
//此命令为cmd命令,可以根据其IP获取mac等地址
process.StartInfo.Arguments = " -a " + GetClientIP(); //设置nbtstat的命令执行参数
process.StartInfo.UseShellExecute = false;//不启用外壳启动线程
process.StartInfo.CreateNoWindow = true;//在新窗口中启动
process.StartInfo.RedirectStandardOutput = true;//将程序写入输出流
process.Start();//启动
string output = process.StandardOutput.ReadToEnd();//获取流并以葱头到尾的形式赋值与变量
//length = output.IndexOf("MAC Address = ");
//mac = output.Substring(length + 14, 17);//检索字符串,从索引14开始,长度为17,mac的长度为17
length = output.IndexOf("MAC 地址 = ");//获取字符串以MAC 地址 = 为索引的项
mac = output.Substring(length + 9, 17);//检索字符串,从索9开始,长度为17,mac的长度为17
return mac;
}
/// 获取IP
/// </summary>
/// <returns></returns>
public static string GetClientIP()
{
string clientIP = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (string.IsNullOrEmpty(clientIP))
{
clientIP = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
}
if (string.IsNullOrEmpty(clientIP))
{
clientIP = HttpContext.Current.Request.UserHostAddress;
}
return clientIP;
}
//再送你个获取XP MAC的
public static string GetMac()
{
string mac = "";
int length = 0;
System.Diagnostics.Process process = new System.Diagnostics.Process();//线程类,可以启动关闭一些线程
process.StartInfo.FileName = "nbtstat";//传递启动线程名,命令为nbtstat
//此命令为cmd命令,可以根据其IP获取mac等地址
process.StartInfo.Arguments = " -a " + GetClientIP(); //设置nbtstat的命令执行参数
process.StartInfo.UseShellExecute = false;//不启用外壳启动线程
process.StartInfo.CreateNoWindow = true;//在新窗口中启动
process.StartInfo.RedirectStandardOutput = true;//将程序写入输出流
process.Start();//启动
string output = process.StandardOutput.ReadToEnd();//获取流并以葱头到尾的形式赋值与变量
//length = output.IndexOf("MAC Address = ");
//mac = output.Substring(length + 14, 17);//检索字符串,从索引14开始,长度为17,mac的长度为17
length = output.IndexOf("MAC 地址 = ");//获取字符串以MAC 地址 = 为索引的项
mac = output.Substring(length + 9, 17);//检索字符串,从索9开始,长度为17,mac的长度为17
return mac;
}

2023-07-25 广告
StormProxies是一家国内优质海外HTTP代理商,拥有一个庞大的IP资源池,覆盖200多个地区,IP数量大且匿名度高。其优点还包括超高并发、稳定高效、技术服务等特点,同时提供HTTP、HTTPS以及SOCKS5协议支持。此外,Sto...
点击进入详情页
本回答由Storm代理提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询