Welcome to 16892 Developer Community-Open, Learning,Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

import subprocess
interface = 'wlan0'
address = '00:11:22:33:44:66'

subprocess.call('ifconfig' + interface + 'down', shell=True)
subprocess.call('ifconfig' + interface + 'hw ether' + address, shell=True)
subprocess.call('ifconfig' + interface + 'up', shell=True)

Output:

for output please check the image please


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
482 views
Welcome To Ask or Share your Answers For Others

1 Answer

'ifconfig' + interface + 'down'

Is not spaced and will produce a single long word ifconfigwlan0down instead of the desired ifconfig wlan0 down

you have two aproaches to fix this: Either add spaces 'ifconfig ' + interface + ' down'

Or the more correct solution is to separate your parameters into a list as that is what the subprocess module expects:

subprocess.call(['ifconfig', interface, 'down'], shell=True)
subprocess.call(['ifconfig', interface, 'hw', 'ether', address], shell=True)
subprocess.call(['ifconfig', interface, 'up'], shell=True)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to 16892 Developer Community-Open, Learning and Share
...