-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathclassroom.py
73 lines (67 loc) · 2.72 KB
/
classroom.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
# -*- coding: utf-8 -*-
#
# Date : 2016-05-09
# Author : 红绯鱼
import wmi
import random
print u'欢迎使用红绯鱼の修改IP程序 <你现在位于教学楼>'
wmiService = wmi.WMI()
colNicConfigs = wmiService.Win32_NetworkAdapterConfiguration(IPEnabled = True)
if len(colNicConfigs) < 1:
print u'没有找到可用的网络适配器'
exit()
for i in xrange(len(colNicConfigs)):
objNicConfig = colNicConfigs[i]
print objNicConfig.Index
print objNicConfig.SettingID
print objNicConfig.Description.encode("cp936")
if colNicConfigs[i].SettingID=='{B324793C-DD04-43BB-8DD0-B17BCBED9DC2}' :
break
print u"无线网卡信息: "
print u'IP: ', ', '.join(objNicConfig.IPAddress)
if objNicConfig.DefaultIPGateway!=None and objNicConfig.DNSServerSearchOrder!=None:
print u'掩码: ', ', '.join(objNicConfig.IPSubnet)
print u'网关: ', ', '.join(objNicConfig.DefaultIPGateway)
print u'DNS: ', ', '.join(objNicConfig.DNSServerSearchOrder)
def change(ip_last):
print u"随机选择IP为"+str(ip_last)
arrIPAddresses = ['10.104.111.'+str(ip_last)]
arrSubnetMasks = ['255.255.255.0']
arrDefaultGateways = ['10.104.111.1']
arrGatewayCostMetrics = [1]
arrDNSServers = ['114.114.114.114', '114.114.115.115']
intReboot = 0
returnValue = objNicConfig.EnableStatic(IPAddress = arrIPAddresses, SubnetMask =arrSubnetMasks)
if returnValue[0] == 0 or returnValue[0] == 1:
print u'设置IP成功'
intReboot += returnValue[0]
else:
print u'修改失败: IP或子网掩码设置发生错误'
return
returnValue = objNicConfig.SetGateways(DefaultIPGateway = arrDefaultGateways, GatewayCostMetric = arrGatewayCostMetrics)
if returnValue[0] == 0 or returnValue[0] == 1:
print u'设置网关成功'
intReboot += returnValue[0]
else:
print u'修改失败: 网关设置发生错误'
return
returnValue = objNicConfig.SetDNSServerSearchOrder(DNSServerSearchOrder = arrDNSServers)
if returnValue[0] == 0 or returnValue[0] == 1:
print u'设置DNS成功'
intReboot += returnValue[0]
else:
print str(returnValue)+u'修改失败: DNS设置发生错误'
return
# print 'IP: ', ', '.join(objNicConfig.IPAddress)
# if objNicConfig.DefaultIPGateway!=None :
# print '掩码: ', ', '.join(objNicConfig.IPSubnet)
# print '网关: ', ', '.join(objNicConfig.DefaultIPGateway)
# print 'DNS: ', ', '.join(objNicConfig.DNSServerSearchOrder)
if intReboot > 0:
print u'需要重新启动计算机'
print u'修改结束'
rand=random.randint(1, 254)
change(rand)
while(raw_input(u'是否可以上网?(y/n)')!='y'):
rand=random.randint(1, 254)
change(rand)