1 import sys
2 import os,tempfile,webbrowser,random
3 import wmi,time
4 from twisted.web import client
5 from twisted.internet import reactor
6
7 def ModifyIP(ip, mask, gateway):
8 wmiService = wmi.WMI()
9 colNicConfigs = wmiService.Win32_NetworkAdapterConfiguration(IPEnabled = True)
10
11 if len(colNicConfigs) < 1:
12 print '娌℃湁鎵懼埌鍙敤鐨勭綉緇滈傞厤鍣?/span>'
13 exit()
14
15 #閫夋嫨瑕佷慨鏀圭殑緗戝崱
16 objNicConfig = colNicConfigs[0]
17
18 print '鐩墠閰嶇疆涓猴細'
19 print 'IP: %s' % objNicConfig.IPAddress
20 print '鎺╃爜: %s' % objNicConfig.IPSubnet
21 print '緗戝叧: %s' % objNicConfig.DefaultIPGateway
22
23 arrIPAddresses = [ip]
24 arrSubnetMasks = [mask]
25 arrDefaultGateways = [gateway]
26 arrGatewayCostMetrics = [1]
27
28 intReboot = 0
29
30 returnValue = objNicConfig.EnableStatic(IPAddress = arrIPAddresses, SubnetMask = arrSubnetMasks)
31 print returnValue
32 if returnValue[0] == 0:
33 print '璁劇疆IP鎴愬姛'
34 elif returnValue[0] == 1:
35 print '璁劇疆IP鎴愬姛'
36 intReboot += 1
37 else:
38 print '淇敼IP澶辮觸: IP璁劇疆鍙戠敓閿欒'
39 exit()
40
41 returnValue = objNicConfig.SetGateways(DefaultIPGateway = arrDefaultGateways, GatewayCostMetric = arrGatewayCostMetrics)
42 if returnValue[0] == 0:
43 print '璁劇疆緗戝叧鎴愬姛'
44 elif returnValue[0] == 1:
45 print '璁劇疆緗戝叧鎴愬姛'
46 intReboot += 1
47 else:
48 print '淇敼緗戝叧澶辮觸: 緗戝叧璁劇疆鍙戠敓閿欒'
49 exit()
50
51 if intReboot > 0:
52 print '闇瑕侀噸鏂板惎鍔ㄨ綆楁満'
53 else:
54 print ''
55 print '淇敼鍚庣殑閰嶇疆涓猴細'
56 print 'IP: %s' % objNicConfig.IPAddress
57 print '鎺╃爜: %s' % objNicConfig.IPSubnet
58 print '緗戝叧: %s' % objNicConfig.DefaultIPGateway
59 print ''
60
61
62
63 def handleError(failure):
64 print "Error:",failure.getErrorMessage()
65 reactor.stop()
66 print "--------------Vote failed one time---------------"
67
68 def showPage(pageData):
69 print pageData
70 reactor.stop()
71 print "--------------Voted success one time---------------"
72
73 def vote():
74 voteURL="http://10.14.4.9:8081/plus/d3vote/new/vote/dovote.jsp?VoteIds=4&type=0"
75
76 postRequest=client.getPage(voteURL,method="POST")
77 postRequest.addCallback(showPage).addErrback(handleError)
78 reactor.run()
79
80 def main():
81 sysargv = sys.argv
82 prefix = sys.argv[1]
83 start = sys.argv[2]
84 end = sys.argv[3]
85 mask = sys.argv[4]
86 gateway = sys.argv[5]
87
88 ipList = []
89 for i in range(int(start), int(end) + 1):
90 ipList.append(prefix + str(i))
91
92 for ip in ipList:
93 ModifyIP(ip, mask, gateway)
94 vote()
95 time.sleep(3)
96
97
98 if __name__=="__main__":
99 main()
100

]]>