用python获取cmd下的相关信息
简单的python代码获取IP配置
import socket
import requests
import subprocess
import re
#检查基本的IP配置等
output = subprocess.Popen(["ipconfig", "/all"], stdout=subprocess.PIPE).communicate()[0].decode("gbk")
print(output)
print("IP地址如下:")
IP=re.findall(r".*IPv4.*",output)
for i in range(len(IP)):
print(IP[i])
print("子网掩码如下:")
m=re.findall(r".*子网掩码.*",output)
for i in range(len(m)):
print(m[i])
print("默认网关如下:")
de=re.findall(r".*默认网关.*",output)
for i in range(len(de)):
if (i==len(de)-1):
print(de[i])
print("DNS服务器如下:")
DNS=re.findall(r".*DNS 服务器.*",output)
for i in range(len(DNS)):
print(DNS[i])
下面的代码是检查远程协助服务和网络共享
#检查远程协助服务
output = subprocess.Popen('netstat -ano', stdout=subprocess.PIPE).communicate()[0].decode("gbk")
work=re.findall(r"3389",output)
if work:
print("远程协助服务开启")
else:
print("远程协助服务未开启")
#检查盘符共享
output = subprocess.Popen('net share', stdout=subprocess.PIPE).communicate()[0].decode("gbk")
share=re.findall(r"共享|share",output)
print(output)
if share:
print("存在盘符共享")
else:
print("盘符共享关闭")