0

I'm learning python programming and wanted to try out some scripts in changing MAC Addresses in linux but i keep getting the following error:

/bin/sh : 1 : ifconfigeth0down : not found
/bin/sh : 1 : ifconfigeth0hw : not found
/bin/sh : 1 : ifconfigeth0up : not found

Would appreciate if anyone can help me out on this, thank you.

The code is as follows:

#!/usr/bin/env python

import_subprocess

interface = input("interface >")

new_mac = input("new MAC >")

subprocess.call("ifconfig" + interface + "down", shell=True)

subprocess.call("ifconfig + interface + "hw ether" + new_mac, shell=True)

subprocess.call("ifconfig" + interface + "up", shell=True)*
Faris Roslin
  • 11
  • 1
  • 1
  • 5
    Put a space after "ifconfig" making it "ifconfig ". Same for "down" but this time, put the space before. – Cornholio Jan 29 '19 at 21:32
  • 1
    Put the command in a variable and print it before you run it. That will make it easier to see what you're doing wrong. – that other guy Jan 29 '19 at 21:49
  • It would be better to use a list instead of a string. – Barmar Jan 29 '19 at 22:00
  • Possible duplicate of [Print without space in Python](https://stackoverflow.com/q/12700558/608639). Also see [How to step through Python code to help debug issues?](https://stackoverflow.com/q/4929251/608639) – jww Jan 30 '19 at 05:14

1 Answers1

1

The problem is that you don't have spaces around the arguments to the command.

But it would be better to avoid shell parsing entirely, by passing a list instead of a string.

subprocess.call(["ifconfig", interface, "down"])
supprocess.call(["ifconfig", interface, "hw", "ether", new_mac])
subprocess.call(["ifconfig", interface, "up"])
Barmar
  • 741,623
  • 53
  • 500
  • 612