forked from shack2/SNETCracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTool.cs
More file actions
152 lines (141 loc) · 5.34 KB
/
Tool.cs
File metadata and controls
152 lines (141 loc) · 5.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
using Microsoft.Win32;
using System;
using System.IO;
using System.Net;
using System.Text;
using System.Net.NetworkInformation;
using System.Management;
namespace Tools
{
class Tool
{
/**
* 获取系统相关唯一ID,用于统计
*/
public static String getSystemSid()
{
String sid = "";
try
{
//获得系统名称
RegistryKey rk = Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Windows NT\\CurrentVersion");
sid = rk.GetValue("ProductName").ToString();
rk.Close();
//获得系统唯一号,系统安装id和mac组合
sid += "_";
var officeSoftware = new ManagementObjectSearcher("SELECT ID, ApplicationId, PartialProductKey, LicenseIsAddon, Description, Name, OfflineInstallationId FROM SoftwareLicensingProduct where PartialProductKey <> null");
var result = officeSoftware.Get();
foreach (var item in result)
{
String c = item.GetPropertyValue("name").ToString();
if (item.GetPropertyValue("name").ToString().StartsWith("Windows"))
{
sid += item.GetPropertyValue("OfflineInstallationId").ToString() + "_";
break;
}
}
}
catch (Exception e)
{
sid += "ex_";
}
String mac = "";
try
{
NetworkInterface[] fNetworkInterfaces = NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface adapter in fNetworkInterfaces)
{
String fCardType = "o";
String fRegistryKey = "SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\" + adapter.Id + "\\Connection";
RegistryKey rk = Registry.LocalMachine.OpenSubKey(fRegistryKey, false);
if (rk != null)
{
String fPnpInstanceID = rk.GetValue("PnpInstanceID", "").ToString();
int fMediaSubType = Convert.ToInt32(rk.GetValue("MediaSubType", 0));
if (!String.IsNullOrEmpty(fPnpInstanceID) && fPnpInstanceID.StartsWith("PCI"))
{
if (fMediaSubType == 2)
{
fCardType = "w";
}
else
{
fCardType = "n";
}
mac = fCardType + ":" + adapter.GetPhysicalAddress().ToString() + "--";
}
}
}
if (mac.EndsWith("--"))
{
mac = mac.Substring(0, mac.Length - 2);
}
}
catch
{
}
return sid + mac;
}
public static void HttpDownloadFile(string url, string path)
{
// 设置参数
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
//发送请求并获取相应回应数据
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
//直到request.GetResponse()程序才开始向目标网页发送Post请求
Stream responseStream = response.GetResponseStream();
//创建本地文件写入流
Stream stream = new FileStream(path, FileMode.Create);
byte[] bArr = new byte[1024];
int size = responseStream.Read(bArr, 0, (int)bArr.Length);
while (size > 0)
{
stream.Write(bArr, 0, size);
size = responseStream.Read(bArr, 0, (int)bArr.Length);
}
stream.Close();
responseStream.Close();
}
public static String getHtml(String url, int timeout)
{
String html = "";
HttpWebResponse response = null;
StreamReader sr = null;
HttpWebRequest request = null;
try
{
//设置模拟http访问参数
Uri uri = new Uri(url);
request = (HttpWebRequest)WebRequest.Create(uri);
request.Accept = "*/*";
request.Method = "GET";
request.Timeout = timeout * 1000;
request.AllowAutoRedirect = false;
response = (HttpWebResponse)request.GetResponse();
sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
//读取服务器端返回的消息
html = sr.ReadToEnd();
}
catch (Exception e)
{
FileTool.log(e.Message);
}
finally
{
if (sr != null)
{
sr.Close();
}
if (response != null)
{
response.Close();
}
if (request != null)
{
request.Abort();
}
}
return html;
}
}
}