Script to change ip address on windows

前端 未结 4 1926
名媛妹妹
名媛妹妹 2020-12-02 23:56

I use my computer to communicate with a piece of hardware via ethernet. To communicate with this device I set my ip to 192 168 0 11, subnet mask to 255 255 255 0, and defaul

4条回答
  •  天命终不由人
    2020-12-03 00:45

    You can use the subprocess module to start

    netsh interface ip set address [params]
    

    Start this from the commandline (without[params]) to get some help how to use it. Then you can do

    import subprocess
    subprocess.call("netsh interface ip set address ....".split())
    

    Update:

    For those who's too busy to rtfm,

    netsh interface ip set address lan static 192.168.0.100 255.255.255.0
    netsh interface ip set address lan dhcp
    

    here lan is the name of the network interface to configure, 192.168.0.100 is ip address, 255.255.255.0 is network mask. The first command sets static address, the second reverts to dhcp.

提交回复
热议问题