【python】静态IP修改器

来源:互联网 发布:bp算法推导 编辑:程序博客网 时间:2024/05/17 03:44

修改IP的机子。。得跟刷票机一起用。

#encoding=utf-8#netsh int ip set add 本地连接 static 10.7.18.28 255.255.255.0 10.7.18.1 1#netsh int ip set dns 本地连接 static 61.153.34.28#netsh int ip set add 本地连接 static 10.7.18.248 255.255.255.0 10.7.18.1 1import sys;import os;if __name__ == '__main__':    try:        ip_init = raw_input("Input the Init IP:")        mask = raw_input("Input yout subnet mask:")        gate = raw_input("Input your network gate:")        f = open("WindowsApplication1\\001.bat", "w")        f.write(            "netsh int ip set add 本地连接 static " + ip_init + " " + mask + " " + gate + " 1\nnetsh int ip set dns 本地连接 static 61.153.34.28")        f.close()        for i in range(2, 254):            gg = ip_init.split(".")            f = open("WindowsApplication1\\" + str("%03d" % i) + ".bat", "w")            f.write("netsh int ip set add 本地连接 static " + ".".join(gg[0:3]) + "." + str(\                i) + "" + " " + mask + " " + gate + " 1")            f.close()    except Exception, ex:        print "system error:" + ex;    finally:        os.system("pause")