How to rename Network Interface name - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: How to rename Network Interface name (/thread-15764.html) |
How to rename Network Interface name - aniyanetworks - Jan-30-2019 Hello Everyone, I have a Batch script which is working fine, but I want to achieve the same in the python3.7 script. Please help. netsh interface set interface name="OLDNIC" newname="NEWNIC" I had a Pything script which was doing Disable the Wifi but how i can change the name? by using Pything Script. subprocess.call(['netsh', 'interface', 'set', 'interface', 'Wi-Fi', 'disabled'])Please advise. Thank you ANS RE: How to rename Network Interface name - gontajones - Jan-30-2019 Try this: import subprocess cmd = 'netsh interface set interface name="OLDNIC" newname="NEWNIC"' subprocess.call([cmd], shell=True) RE: How to rename Network Interface name - aniyanetworks - Jan-30-2019 (Jan-30-2019, 04:27 PM)gontajones Wrote: Try this: import os import subprocess cmd = 'netsh interface set interface name="TPALAN" newname="TPALAN2"' subprocess.call([cmd], shell=True) os.system("netsh interface show interface")
RE: How to rename Network Interface name - buran - Jan-30-2019 To disable Wi-Fi >>> import subprocess >>> subprocess.call(['netsh', 'interface', 'set', 'interface', 'name="Wi-Fi"', 'admin="DISABLED"']) 0You need to run cmd in elevated mode (i.e. Run As Administrator) Change the name if the adapter name is not Wi-Fi, e.g. Wireless Network Connection, etc. Use this as example how to rename interface >>> subprocess.call(['netsh', 'interface', 'set', 'interface', 'name="TPALAN"', 'newname="TPALAN2"']) RE: How to rename Network Interface name - aniyanetworks - Jan-30-2019 (Jan-30-2019, 04:54 PM)buran Wrote: To disable Wi-Fi Perfect Thanks Buran. One more questions: I am trying to get input function to get Interface name from User, but it doesn't accept input value. can you please help? import subprocess import os changeName=input("Enter the Interface name:") print(changeName) subprocess.call(['netsh', 'interface', 'set', 'interface', 'name="Wi-Fi"', 'newname=changeName']) os.system("netsh interface show interface") It doesn't accept the Value from Input function.Please help. Thank you RE: How to rename Network Interface name - nilamo - Jan-30-2019 That's simple string formatting. Ignore the fact that it's a network interface, or a different command. How would you just print it out to the screen? RE: How to rename Network Interface name - buran - Jan-30-2019 if using 3.6+ use f-strings subprocess.run(['netsh', 'interface', 'set', 'interface', 'name="Wi-Fi"', f'newname="{changeName}"'])if using lower version subprocess.run(['netsh', 'interface', 'set', 'interface', 'name="Wi-Fi"', 'newname="{}"'.format(changeName)])for greater readability you may want to make this before the call import subprocess change_name = input("Enter the Interface name:") new_name = 'newname="{}"'.format(change_name) # new_name = f'newname="{change_name}"' subprocess.run(['netsh', 'interface', 'set', 'interface', 'name="Wi-Fi"', new_name]) subprocess.run(['netsh', 'interface', 'show', 'interface'])don't use os.system - it's depreciated, use subprocess.call or even better subprocess.run
RE: How to rename Network Interface name - aniyanetworks - Jan-30-2019 (Jan-30-2019, 05:33 PM)buran Wrote: if using 3.6+ use f-strings |