.NET获取机器信息
/// <summary>
/// using System.Web;
/// using System.Management;
/// </summary>
public static void main()
{
//客户端ip:
HttpContext.Current.Request.ServerVariables.Get("Remote_Addr").ToString();
//客户端主机名:
HttpContext.Current.Request.ServerVariables.Get("Remote_Host").ToString();
//客户端浏览器IE:
string Browser = HttpContext.Current.Request.Browser.Browser;
//客户端浏览器 版本号:
int MajorVersion = System.Web.HttpContext.Current.Request.Browser.MajorVersion;
//客户端操作系统:
string Platform = System.Web.HttpContext.Current.Request.Browser.Platform;
//服务器ip:
HttpContext.Current.Request.ServerVariables.Get("Local_Addr").ToString();
//端口:
HttpContext.Current.Request.Url.Port.ToString();
//服务器名:
System.Web.HttpContext.Current.Request.ServerVariables.Get("Server_Name").ToString(); //获取网卡的地址、本地的IP地址
string stringMAC = "";
string stringIP = "";
ManagementClass MC = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection MOC = MC.GetInstances();
foreach (ManagementObject MO in MOC)
{
if ((bool)MO["IPEnabled"] == true)
{
stringMAC += MO["MACAddress"].ToString(); //获取网卡的地址
string[] IPAddresses = (string[])MO["IPAddress"]; //获取本地的IP地址
if (IPAddresses.Length > )
{
stringIP = IPAddresses[];
}
}
}
//获取远程客户端的网卡物理地址(MAC)(本机测试不了)
string MAC = GetMac(HttpContext.Current.Request.UserHostAddress.ToString()); //cpu序列号
string cpuInfo = "";
ManagementClass cimobject = new ManagementClass("Win32_Processor");
ManagementObjectCollection moc = cimobject.GetInstances();
foreach (ManagementObject mo in moc)
{
cpuInfo = mo.Properties["ProcessorId"].Value.ToString();
string cpu = "cpu序列号:" + cpuInfo.ToString();
} //获取硬盘ID
String HDid;
ManagementClass cimobject1 = new ManagementClass("Win32_DiskDrive");
ManagementObjectCollection moc1 = cimobject1.GetInstances();
foreach (ManagementObject mo in moc1)
{
HDid = (string)mo.Properties["Model"].Value;
string yinpan = "硬盘序列号:" + HDid.ToString();
} //获取网卡硬件地址
ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc2 = mc.GetInstances();
foreach (ManagementObject mo in moc2)
{
if ((bool)mo["IPEnabled"] == true)
{
string yinpan = "MAC address/t{0}" + mo["MacAddress"].ToString();
}
mo.Dispose();
}
} /// <summary>
/// 获取远程客户端的网卡物理地址(MAC)
/// using System.Diagnostics;
/// using System.Text.RegularExpressions;
/// </summary>
/// <param name="IP"></param>
/// <returns></returns>
private static string GetMac(string IP) //para IP is the client's IP
{
string dirResults = "";
ProcessStartInfo psi = new ProcessStartInfo();
Process proc = new Process();
psi.FileName = "nbtstat";
psi.RedirectStandardInput = false;
psi.RedirectStandardOutput = true;
psi.Arguments = "-A " + IP;
psi.UseShellExecute = false;
proc = Process.Start(psi);
dirResults = proc.StandardOutput.ReadToEnd();
proc.WaitForExit();
dirResults = dirResults.Replace("/r", "").Replace("/n", "").Replace("/t", ""); Regex reg = new Regex("Mac[ ]{0,}Address[ ]{0,}=[ ]{0,}(?<key>((.)*?))__MAC", RegexOptions.IgnoreCase | RegexOptions.Compiled);
Match mc = reg.Match(dirResults + "__MAC"); if (mc.Success)
{
return mc.Groups["key"].Value;
}
else
{
reg = new Regex("Host not found", RegexOptions.IgnoreCase | RegexOptions.Compiled);
mc = reg.Match(dirResults);
if (mc.Success)
{
return "Host not found!";
}
else
{
return "";
}
}
}
.NET获取机器信息的更多相关文章
- python获取机器信息脚本(网上寻找的)
获取机器信息(待测试) # -*- coding: UTF-8 -*- import psutil import json import os import socket import struct ...
- 通过WMI获取机器信息
PerformanceCounter的介绍就不多说了,MSDN上介绍的很详细: https://msdn.microsoft.com/zh-cn/library/system.diagnostics. ...
- c# WMI获取机器硬件信息(硬盘,cpu,内存等)
using System; using System.Collections.Generic; using System.Globalization; using System.Management; ...
- c# 获取机器硬件信息 (硬盘,cpu,内存等)
using System; using System.Collections.Generic; using System.Globalization; using System.Management; ...
- 浅谈如何获取机器的memory和CPU信息
最近做了一个项目,需要获取机器的CPU和memory的使用情况.花了一些时间网上搜索了一下,自己也做了些测试.总结下来,基本上2种方式:一种是用WMI(2种),另一种是用Performance cou ...
- iOS 整理笔记 获取手机信息(UIDevice、NSBundle、NSLocale)
/* iOS的APP的应用开发的过程中,有时为了bug跟踪或者获取用反馈的需要自动收集用户设备.系统信息.应用信息等等,这些信息方便开发者诊断问题,当然这些信息是用户的非隐私信息,是通过开发ap ...
- python 读取机器信息
本人最近新学python ,用到关于机器的相关信息,经过一番研究,从网上查找资料,经过测试,总结了一下相关的方法. # -*- coding: UTF8 -*- import os import wi ...
- python并发获取snmp信息及性能测试
python & snmp 用python获取snmp信息有多个现成的库可以使用,其中比较常用的是netsnmp和pysnmp两个库.网上有较多的关于两个库的例子. 本文重点在于如何并发的获取 ...
- iOS学习笔记(十三)——获取手机信息(UIDevice、NSBundle、NSLocale)
iOS的APP的应用开发的过程中,有时为了bug跟踪或者获取用反馈的需要自动收集用户设备.系统信息.应用信息等等,这些信息方便开发者诊断问题,当然这些信息是用户的非隐私信息,是通过开发api可以获取到 ...
随机推荐
- 45 Useful JavaScript Tips, Tricks and Best Practices(有用的JavaScript技巧,技巧和最佳实践)
As you know, JavaScript is the number one programming language in the world, the language of the web ...
- 基于 SWTBot 进行 Eclipse GUI 自动化测试
背景简介 在软件开发领域,持续集成和部署对于软件测试自动化提出了越来越高的要求,基于 Eclipse 应用在这一需求中仍然占据重要的组成部分.目前主流的测试自动化工具主要以录制回放的功能为主,辅助以脚 ...
- 如何把iOS代码编译为Android应用
新闻 <iPhone 6/6 Plus中国销量曝光:单月销量650万>:据iSuppli Corp.中国研究总监王阳爆料,iPhone 6和iPhone 6 Plus在国内受欢迎的情况大大 ...
- java中的string字符串中的trim函数的作用
去掉字符串首尾空格 防止不必要的空格导致错误public class test{ public static void main(String[] args) { String str = " ...
- PlatformTransactionManager
Spring Boot 使用事务非常简单,首先使用注解 @EnableTransactionManagement 开启事务支持后,然后在访问数据库的Service方法上添加注解 @Transactio ...
- index rang scan
根:分支的范围,范围块的地址 ----- begin tree dump branch: 0x1000c93 16780435 (0: nrow: 5, level: 1) leaf: 0x10 ...
- session和cookie详解2
http 之session和cookie http://www.cnblogs.com/ForEverKissing/archive/2008/05/23/1205503.html Session简介 ...
- C# 绘图对象 流对象 响应对象关系
- Lowest Common Ancestor in Binary Tree
The problem: Given node P and node Q in a binary tree T. Find out the lowest common ancestor of the ...
- Single Number III——LeetCode
Given an array of numbers nums, in which exactly two elements appear only once and all the other ele ...