forked from Ye0kr1n/mining-inspection-Ver2.0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmining-inspection-C_v2.py
628 lines (572 loc) · 23.1 KB
/
mining-inspection-C_v2.py
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
# -*- coding: UTF-8 -*-
import uuid
import psutil, linecache, ctypes, wmi
import os, datetime, time, platform, sys, socket
import requests, hashlib, json, configparser, xlrd, xlwt
from xml.etree.ElementTree import Element
from xml.etree.ElementTree import SubElement
from xml.etree.ElementTree import ElementTree
from xml.dom.minidom import parse
import pynvml
pool_list = []
Sys_type = platform.system()
pc_name = socket.gethostname()
pc_ip = socket.gethostbyname(socket.gethostname())
configi = configparser.ConfigParser()
conf_path = r'config-c.ini'
def conn_server(serverip, serverport, token, request_data):
header = {
'token': token
}
try:
res = requests.post('http://' + serverip + ':' + serverport, data=request_data, headers=header)
print("[*]Server recv:%s" % res.text)
print("[+]数据已成功发送至服务端")
except:
print("[-]发送数据失败,请查看服务器是否配置正常")
return res
def get_network_connect():
raddr_list = []
connlist = psutil.net_connections()
cache = []
for i in range(0, len(connlist)):
if len(connlist[i].raddr) > 0:
cache.append(connlist[i].raddr[0])
else:
continue
for i in cache:
if i not in raddr_list:
raddr_list.append(i)
else:
continue
list(set(raddr_list))
return raddr_list
def get_network_flow(): # 当前流量特征
if Sys_type == "Windows":
c = wmi.WMI()
for interfacePerTcp in c.Win32_PerfRawData_Tcpip_TCPv4():
sentflow = float(interfacePerTcp.SegmentsSentPersec) # 已发送的流量
receivedflow = float(interfacePerTcp.SegmentsReceivedPersec) # 接收的流量
present_flow = sentflow + receivedflow # 算出当前的总流量
time.sleep(1)
for interfacePerTcp in c.Win32_PerfRawData_Tcpip_TCPv4():
sentflow = float(interfacePerTcp.SegmentsSentPersec) # 已发送的流量
receivedflow = float(interfacePerTcp.SegmentsReceivedPersec) # 接收的流量
per_last_present_flow = sentflow + receivedflow # 算出1秒后当前的总流量
present_network_flow = (per_last_present_flow - present_flow) / 1024
return "%.2f" % present_network_flow
def check_run_file_hash(): # 检测运行中文件的HASH
filepath = "NULL"
c = wmi.WMI()
pathinfo = []
path = []
localfilehash = [] # 本地文件
n = 0
with open("fileHash.list", "r", encoding='gb2312') as f: # 打开文件
data = f.read() # 读取文件
f.close()
filelist = json.loads(data) # Hash特征库
for process in c.Win32_Process():
try:
p = psutil.Process(int(process.ProcessId))
if p.exe() not in path:
path.append(p.exe())
else:
continue
except:
print("%s[-]进程: %s 无法获取目录" % (str(datetime.datetime.now()), p.name()))
for i in path:
try:
with open(i, 'rb') as f:
sha256obj = hashlib.sha256()
sha256obj.update(f.read())
localfilehash.append([i, sha256obj.hexdigest()])
except:
print("%s [-]文件:%s 无法获取hash" % (str(datetime.datetime.now()), i))
f.close()
for i in filelist:
for j in localfilehash:
if filelist[i]['FILEHASH'] == j[1]:
print("%s [!]查找到文件:%s 挖矿类型为: %s" % (str(datetime.datetime.now()), j[0], filelist[i]['TYPE']))
filepath = j[0]
n = 1
break
pathinfo.append(localfilehash)
return {"check_run_file_hash": n, "content": [pathinfo, filepath]}
def net_is_used(port, ip='127.0.0.1'): # 端口检测
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
s.connect((ip, port))
s.shutdown(2)
print('[!]黑名单端口 %s:%d 处于开放状态' % (ip, port))
return [True, port]
except:
print('[+]未检测到黑名单端口 %s:%d 开放' % (ip, port))
return False
def check_free_space_mb(): # C盘剩余量
folder = 'C:\\'
if platform.system() == 'Windows': # 区分系统
free_bytes = ctypes.c_ulonglong(0)
ctypes.windll.kernel32.GetDiskFreeSpaceExW(ctypes.c_wchar_p(folder), None, None, ctypes.pointer(free_bytes))
disk_free = round(free_bytes.value / 1024 / 1024 / 1024, 2)
if disk_free < 1:
n = 1
else:
n = 0
else:
st = os.statvfs(folder)
disk_free = st.f_bavail * st.f_frsize / 1024 / 1024
if disk_free < 1:
n = 1
else:
n = 0
return {"check_free_space_mb": n, "content": disk_free}
def check_port_list(): # 端口检测
conte = linecache.getlines('port.list') # 端口在port文件中
check_list = []
n=0
for i in range(len(conte)): # 病毒一般占用4位数端口,端口范围可选,或针对端口关闭
if net_is_used(int(conte[i])):
n = 1
check_list.append(conte[i].replace('\n', ''))
else:
continue
return {"check_port_list": n, "content": check_list}
def check_memcpu(): # 获取内存以及CPU数据
global n
data = psutil.virtual_memory()
total = data.total # 总内存,单位为byte
free = data.available # 可以内存
memory = "%d" % (int(round(data.percent))) + "%" # 内存使用率
cpu = "%0.2f" % psutil.cpu_percent(interval=1) + "%" # CPU使用率
pynvml.nvmlInit()
handle = pynvml.nvmlDeviceGetHandleByIndex(0)
meminfo = pynvml.nvmlDeviceGetMemoryInfo(handle)
if int(round(data.percent)) > 75 and psutil.cpu_percent(interval=1) > 75: # 挖矿一个特征
n = 1 # ☆☆☆阈值
else:
n = 0
return {"checkMemCpu": n, "content": [cpu, memory]}
def check_flow(): # 带宽检测
flow = get_network_flow()
if float(flow) > 3000: # 病毒一般占用3033KB/s 阈值
n = 1
else:
n = 0
return {"check_flow": n, 'content': flow} # KB/s
def process_check(): # 进程检测
processchecklist = []
n = 0
pids = psutil.pids()
cont = linecache.getlines('process.list') # 读入进程列表
for j in range(len(cont)):
cont[j] = cont[j][:len(cont[j]) - 1]
for pid in pids:
try:
p = psutil.Process(pid)
if p.name() not in processchecklist:
processchecklist.append(p.name())
else:
continue
except:
print("[-]%s pid:%s 获取名称失败,可尝试重新运行该程序" % (str(datetime.datetime.now()), str(pid)))
# print(p.name())
for j in range(len(cont)):
if p.name() == cont[j]:
n = 1
return {"process_check": n, "content": processchecklist}
def pool_conn_check(): # 外联ip黑名单检测
connect = get_network_connect()
get_pool_list = linecache.getlines('PoolList.list')
n = 0
for i in connect:
if '#' in i:
continue
if i in get_pool_list:
n = 1
else:
continue
return {"pool_connect_check": n, "content": connect}
def getAvailableId(type="min"):
try:
pynvml.nvmlInit()
deviceCount = pynvml.nvmlDeviceGetCount()
current_gpu_unit_use = []
for id in range(deviceCount):
n=0
handle = pynvml.nvmlDeviceGetHandleByIndex(id)
use = pynvml.nvmlDeviceGetUtilizationRates(handle)
if use.memory < 80: # 首先保证有可用内存, 然后选择运行着比较小计算量的GPU
if use.gpu > 90:
current_gpu_unit_use.append(use.gpu)
n=1
else:
current_gpu_unit_use.append(use.gpu)
except:
n=0
current_gpu_unit_use.append(str(0))
pynvml.nvmlShutdown()
print("[+]GPU 占用: %s" % current_gpu_unit_use[0]+'%')
return [current_gpu_unit_use,n]
def update_pool_list():
pool_list1 = []
pool_list2 = []
new_pool_list = []
r = requests.get(url='https://reputation.alienvault.com/reputation.data', timeout=100)
with open("./cache/reputation.data", "wb+") as code:
code.write(r.content)
r = requests.get(url='https://myip.ms/files/blacklist/general/latest_blacklist.txt', timeout=100)
with open("./cache/latest_blacklist.txt", "wb+") as code:
code.write(r.content)
pool_list_one = linecache.getlines('./cache/reputation.data')
for i in pool_list_one:
pool_list1.append(i.split('#')[0])
pool_list_two = linecache.getlines('./cache/latest_blacklist.txt')
for i in range(13, len(pool_list_two)):
pool_list2.append(pool_list_two[i].split('\t\t\t #')[0])
for i in pool_list1:
if i not in new_pool_list:
new_pool_list.append(i)
else:
continue
for i in pool_list2:
if i not in new_pool_list:
new_pool_list.append(i)
else:
continue
f = open("./PoolList.list", "w+")
f.write("#UpdateTime:%s" % str(datetime.datetime.now()))
for i in new_pool_list:
f.write(i + '\r')
f.close()
code.close()
try:
code.close()
os.remove('./cache/latest_blacklist.txt')
os.remove('./cache/reputation.data')
except:
print("[-]缓存文件移除失败,如有需要请手动删除./cache/目录下的文件")
def banner():
print(" __ __ _ _ _____ _ _ ___ ")
print(" | \/ (_) (_) / ____| | | (_) |__ \ ")
print(" | \ / |_ _ __ _ _ __ __ _ | (___ _ __ ___ ___| |_ _ ___ _ __ __ __ ) |")
print(" | |\/| | | '_ \| | '_ \ / _` | \___ \| '_ \ / _ \/ __| __| |/ _ \| '_ \ \ \ / // / ")
print(" | | | | | | | | | | | | (_| | ____) | |_) | __/ (__| |_| | (_) | | | | \ V // /_ ")
print(" |_| |_|_|_| |_|_|_| |_|\__, | |_____/| .__/ \___|\___|\__|_|\___/|_| |_| \_/|____|")
print(" __/ | | | ")
print(" |___/ |_| ")
print("\t\t\t\t\tMining Spection v2")
print("\t\t\t\t\tPowered by Ye0kr1n")
print("\t\t\t\t\t2022-3-6")
def checklist(): # 主检测模块
check_ans = {}
ans = []
n = 0
checkcm = check_memcpu() # return {"checkMemCpu": n, "content": [cpu,memory]}
print("系统类型为:%s" % Sys_type)
check_ans['systemtype'] = Sys_type
check_ans['pc_name'] = pc_name
check_ans['pc_ip'] = pc_ip
check_ans['CPU'] = checkcm['content'][0]
check_ans['Memory'] = checkcm['content'][1]
if checkcm['checkMemCpu'] == 0:
print("%s[+]CPU以及内存检测通过" % str(datetime.datetime.now()))
else:
print("%s[!]CPU以及内存检测不通过" % str(datetime.datetime.now()))
ans.append('CPU')
ans.append('Memory')
n = 1
check_ans['GPU']=getAvailableId()
if check_ans['GPU'][1]==1:
print("%s[!]GPU检测不通过" % str(datetime.datetime.now()))
n=1
ans.append('GPU')
else:
print("%s[+]GPU检测通过" % str(datetime.datetime.now()))
checkfree = check_free_space_mb() # "check_free_space_mb": n, "content": disk_free
check_ans['Disk'] = checkfree['content']
if checkfree['check_free_space_mb'] == 0:
print("%s[+]磁盘检测通过" % str(datetime.datetime.now()))
else:
print("%s[!]磁盘检测不通过" % str(datetime.datetime.now()))
n = 1
ans.append('Disk')
processc = process_check() # "process_check": n, "content": processchecklist
check_ans['Process'] = processc['content']
if processc['process_check'] == 0:
print("%s[+]进程检测通过" % str(datetime.datetime.now()))
else:
print("%s[!]进程检测不通过" % str(datetime.datetime.now()))
n = 1
ans.append('Process')
checkport = check_port_list() # "check_port_list": n, "content":check_list
check_ans['Port'] = checkport['content']
if checkport['check_port_list'] == 0:
print("%s[+]开放端口检测通过" % str(datetime.datetime.now()))
else:
print("%s[!]开放端口检测不通过" % str(datetime.datetime.now()))
n = 1
ans.append('Port')
process_hash = check_run_file_hash() # "check_run_file_hash": n, "content": pathinfo
check_ans['process_hash'] = process_hash['content']
if process_hash['check_run_file_hash'] == 0:
print("%s[+]进程HASH检测通过" % str(datetime.datetime.now()))
else:
print("%s[!]进程HASH检测不通过" % str(datetime.datetime.now()))
n = 1
ans.append('process_hash')
flow = check_flow() # "check_flow": n, 'content':flow
check_ans['flow'] = flow['content'] + 'KB/s'
if flow['check_flow'] == 0:
print("%s[+]带宽占用检测通过" % str(datetime.datetime.now()))
else:
print("%s[!]带宽占用检测不通过" % str(datetime.datetime.now()))
n = 1
ans.append('flow')
polconn = pool_conn_check() # {"pool_connect_check": n, "content": connect}
check_ans['NetWorkConnect'] = polconn['content']
if polconn['pool_connect_check'] == 0:
print("%s[+]外联检测通过" % str(datetime.datetime.now()))
else:
print("%s[!]外联检测不通过" % str(datetime.datetime.now()))
n = 1
ans.append('NetWorkConnect')
print("%s[+]所有项目检查完成" % str(datetime.datetime.now()))
return [check_ans, ans, n]
# def report(modes):
# if modes == 'host':
# print("%s[+]当前模式为单主机模式" % str(datetime.datetime.now()))
# elif modes == 'net':
# print("%s[+]当前模式为网络模式" % str(datetime.datetime.now()))
# elif modes == 'offline':
# print("%s[+]当前模式为离线核查模式" % str(datetime.datetime.now()))
def e2chinese(en):
name = {
'CPU': 'CPU',
'Memory': '内存',
'Disk': '磁盘',
'Process': '进程',
'Port': '端口',
'process_hash': '进程对应HASH',
'flow': '带宽占用',
'NetWorkConnect': '网络外联',
'GPU':'显卡'
}
return name[en]
def mode_onlinecheck():
check_ans = checklist()
print("[+]单主机检查已完成")
print("[+]检查信息如下:")
print("系统类型:%s" % os)
print("CPU:%s" % check_ans[0]['CPU'])
print("内存占用:%s" % check_ans[0]['Memory'])
print("GPU:%s" %check_ans[0]['GPU'][0])
print("磁盘占用:%s" % check_ans[0]['Disk'])
print("本地运行中进程信息:")
for i in check_ans[0]['Process']:
print("\t" + i)
print("异常端口信息:%s" % check_ans[0]['Port'])
print("进程对应HASH信息:")
for i in check_ans[0]['process_hash'][0][0]:
print("\t[+]进程名对应路径:%s 对应hash:%s" % (i[0], i[1]))
if not isinstance(check_ans[0]['process_hash'][1], str):
print("\t[!]发现异常进程:%s" % check_ans[0]['process_hash'][1])
print("带宽占用信息:%s" % check_ans[0]['flow'])
print("本机网络外联信息:")
for i in check_ans[0]['NetWorkConnect']:
print(i)
if len(check_ans[1]) == 0:
print("[+]该主机不存在异常信息")
else:
print("[-]该主机存在异常信息,异常信息如下:")
for i in check_ans[1]:
print("\t[-]%s存在异常" % e2chinese(i))
if check_ans[2] == 1:
print("[!]该主机存在异常信息,请细查")
else:
print("[+]该主机不存在异常信息,检查通过!")
return check_ans
def read_xml(xml_path):
try:
tree = parse(xml_path)
rootNode =tree.documentElement
print(rootNode.nodeName)
except Exception as e:
print("读取xml出错\t%s" % e)
def mode_import_xml(path):
print("离线核查模式启动")
try:
path_list = os.listdir(path + '/xml')
except:
print("列目录异常,请重试")
print(path_list)
for i in path_list:
read_xml(os.path.abspath(path + '/xml/' + i))
def mode_offlinecheck():
check_ans = checklist()
print("[+]单主机检查已完成")
print("[+]检查信息如下:")
print("系统类型:%s" % os)
print("CPU:%s" % check_ans[0]['CPU'])
print("GPU:%s" %check_ans[0]['GPU'][0])
print("内存占用:%s" % check_ans[0]['Memory'])
print("磁盘占用:%s" % check_ans[0]['Disk'])
print("本地运行中进程信息:")
for i in check_ans[0]['Process']:
print("\t" + i)
print("异常端口信息:%s" % check_ans[0]['Port'])
print("进程对应HASH信息:")
for i in check_ans[0]['process_hash'][0][0]:
print("\t[+]进程名对应路径:%s 对应hash:%s" % (i[0], i[1]))
if not len(check_ans[0]['process_hash'][1]) == 4:
print("\t[!]发现异常进程:%s" % check_ans[0]['process_hash'][1])
print("带宽占用信息:%s" % check_ans[0]['flow'])
print("本机网络外联信息:")
for i in check_ans[0]['NetWorkConnect']:
print(i)
if len(check_ans[1]) == 0:
print("[+]该主机不存在异常信息")
else:
print("[-]该主机存在异常信息,异常信息如下:")
for i in check_ans[1]:
print("\t[-]%s存在异常" % e2chinese(i))
if check_ans[2] == 1:
print("[!]该主机存在异常信息,请细察")
else:
print("[+]该主机不存在异常信息,检查通过!")
while (1):
ins = input("请选择导出报告模板:\r\n 1、单主机检测报告 2、离线核查模式xml报告\r\n请输入:")
if ins == "2":
print_xml(check_ans)
print("[+]xml文件已导出,欢迎使用本工具,再会\r\nPowered by Ye0kr1n")
break
elif ins == "1":
print_xls(check_ans)
print('[+]xls表格文件已导出,欢迎使用本工具,再会\r\nPowered by Ye0kr1n')
break
else:
print("[X]输入异常请重新输入")
def print_xls(data):
flag = ''
book = xlwt.Workbook()
writetext = ['主机名', 'IP地址', '系统类型', 'CPU','GPU', '内存', '异常端口', '带宽占用', '系统盘剩余', '本地运行中进程名称', '本地运行中进程路径', '本地运行中进程HASH',
'外连IP', '异常项']
sheet = book.add_sheet(pc_ip + '_' + pc_name)
for i in range(0, len(writetext)):
sheet.write(i, 0, writetext[i])
sheet.write(0, 1, data[0]['pc_name'])
sheet.write(1, 1, data[0]['pc_ip'])
sheet.write(2, 1, data[0]['systemtype'])
sheet.write(3, 1, data[0]['CPU'])
sheet.write(4, 1, str(data[0]['GPU'][0][0])+'%')
sheet.write(5, 1, data[0]['Memory'])
sheet.write(6, 1, data[0]['Port'])
sheet.write(7, 1, str(data[0]['flow']))
sheet.write(8, 1, str(data[0]['Disk']) + 'GB')
for i in range(1, len(data[0]['Process'])):
sheet.write(9, i, data[0]['Process'][i - 1])
for i in range(1, len(data[0]['process_hash'][0][0])):
sheet.write(10, i, data[0]['process_hash'][0][0][i - 1][0])
sheet.write(11, i, data[0]['process_hash'][0][0][i - 1][1])
for i in range(1, len(data[0]['NetWorkConnect'])):
sheet.write(12, i, data[0]['NetWorkConnect'][i - 1])
if len(data[1]) == 0:
sheet.write(13, 1, "该主机不存在异常项")
flag='Sucess'
else:
flag = 'except'
# print(data[1])
x = 1
for i in data[1]:
e2c = e2chinese(i)
sheet.write(13, x, e2c)
x = x + 1
report_path = configi['client_config']['report_path']
try:
file_name = report_path + '/xls/check_report_' + pc_name + '_' + '_' + pc_ip + '_' + str(
uuid.uuid4()) + '_' + flag + '.xls'
book.save(file_name)
except:
print("[!]单主机检查报告保存失败,请尝试重新运行本程序")
def print_xml(data):
root = Element('root')
head = SubElement(root, 'head')
pname = SubElement(head, 'pc_name')
pname.text = data[0]['pc_name']
pcip = SubElement(head, 'pc_ip')
pcip.text = data[0]['pc_ip']
ostype = SubElement(head, 'systemtype')
ostype.text = Sys_type
nowtime = SubElement(head, "check_time")
nowtime.text = str(datetime.datetime.now())
check_list = SubElement(root, 'check_list')
cpu = SubElement(check_list, 'cpu')
cpu.text = data[0]['CPU']
memo = SubElement(check_list, 'Memory')
memo.text = data[0]['Memory']
gpus=SubElement(check_list, 'GPU')
gpus.text=str(data[0]['GPU'][0][0])+'%'
disk = SubElement(check_list, 'Disk_Free')
disk.text = str(float(data[0]['Disk'])) + 'GB'
proc = SubElement(check_list, 'Process')
proc.text = str(data[0]['Process'])
port = SubElement(check_list, 'Port')
port.text = str(data[0]['Port'])
proc_hash = SubElement(check_list, 'Process_HASH')
proc_hash.text = str(data[0]['process_hash'][0][0])
open_port = SubElement(check_list, 'port_check')
PortList = []
for i in data[0]['Port']:
PortList.append(i.replace('\\n', ''))
open_port.text = str(PortList)
flow = SubElement(check_list, 'flow')
flow.text = str(data[0]['flow'])
connect = SubElement(check_list, 'NetworkConnect')
connect.text = (str(data[0]['NetWorkConnect']))
trys = SubElement(check_list, 'trys')
trys.text = str(data[1])
tree = ElementTree(root)
configi.read(conf_path, encoding="utf8")
report_path = configi['client_config']['report_path']
filename = report_path + '/xml/result_' + pc_ip + "_" + pc_name + '_' + str(uuid.uuid4()) + '_outlinecheck.xml'
try:
tree.write(filename, encoding='utf-8')
print("[+]离线文件成功导出,详细路径:%s" % filename)
except:
print("[!]单主机XML保存失败,请尝试重新运行本程序")
def main(): # 主函数
banner()
# ans = []
configi.read(conf_path, encoding="utf8")
server_ip = configi['server_config']['server_ip']
server_port = configi['server_config']['serverport']
server_token = configi['server_config']['token']
write_path = configi['client_config']['report_path']
print("欢迎使用挖矿专项检测工具 V2.0")
print("温馨提示:请在使用前检查ini配置文件是否正常")
print("请先选择检测模式:\r\n1、本地模式\r\n2、服务端模式\r\n3、离线核查模式\r\n4、更新矿池列表信息\r\n")
while True:
mode = input("请输入模式:")
if mode == "1":
print("本地模式启动")
mode_offlinecheck()
break
if mode == "2":
print("服务端模式启动")
print("[+]服务器IP:%s \r\n 服务器端口:%s \r\n" % (server_ip, server_port))
requdata = mode_onlinecheck()
conn_server(server_ip, server_port, "asasasas", str(requdata))
break
if mode == "3":
print("离线核查模式启动")
mode_import_xml(write_path)
break
if mode == "4":
update_pool_list()
break
if not (mode == "1") and not (mode == "2") and not (mode == "3") and not (mode == "4"):
print("输入有误请重新输入\r\n")
# ans = checklist()
# print(ans)
if __name__ == '__main__':
main()