alliciga

          開拓創新,自強不息

          用 Python 實現修改IP地址、投票

          Python 實現 修改 本機IP地址,并自動投票的一段代碼,僅供個人學習研究。

            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 '沒有找到可用的網絡適配器'
           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 

          posted on 2012-07-25 22:27 Alliciga 閱讀(815) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           

          導航

          <2025年7月>
          293012345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          統計

          留言簿

          文章檔案

          相冊

          積分與排名

          最新評論

          主站蜘蛛池模板: 新郑市| 孙吴县| 高平市| 双牌县| 建阳市| 沁源县| 余姚市| 会同县| 探索| 德州市| 喀什市| 深州市| 武清区| 通河县| 海盐县| 扬州市| 德惠市| 喀喇沁旗| 镇赉县| 大安市| 都兰县| 师宗县| 汝南县| 肇东市| 留坝县| 玉山县| 东光县| 东莞市| 大石桥市| 黄平县| 万安县| 玉门市| 望奎县| 中江县| 和林格尔县| 延川县| 前郭尔| 梅河口市| 灵川县| 瑞丽市| 玛沁县|