python related
by zahhak snake shoulder from LinuxQuestions.org on (#5P7D4)
Hi guys
first, does anyone know if there is a python question website like this one, please?
I am trying to learn how to automate Kali with python
my first course is a mac changer
for running the code I need sudo privilege, so I run my code with sudo and have sudo before the code in the script
I always get the same error which is sudo related
SIOCSIFFLAGS: Operation not permitted
which occurs after print(line2) in this code
when i run it without sudo, it askes for password but again i get the same error
Can anyone help me with this please?
code:
#!/usr/bin/python
import subprocess
print("available mac addresses")
print("Ethernet:")
subprocess.call("ifconfig | grep -m1 ether", shell=True)
print("Wlan:0")
subprocess.call("ifconfig | grep ether | tail -1", shell=True)
interface = input("""type w for wlan and e for ethernet
which interface would you like to change > """)
if interface == "w":
interface = "wlan0"
elif interface == "e":
interface = "eth0"
print(interface)
mac = input("new MAC address > ")
print(f"[+] changing {interface} MAC address to {mac}")
print("line1")
subprocess.call(["sudo", "ifconfig", interface, "down"])
print("line2")
subprocess.call(["sudo", "ifconfig", interface, "hw", "ether", mac])
print("line3")
subprocess.call(["sudo", "ifconfig", interface, "up"])
print(f"{interface} changed to {mac}")
subprocess.call("ifconfig | grep ether ", shell=True)
print("Ethernet:")
subprocess.call("ifconfig | grep -m1 ether", shell=True)
print("Wlan:0")
subprocess.call("ifconfig | grep ether | tail -1", shell=True)
output:
(kaliKali)-[~/PycharmProjects/pythonProject/WORK]
$ python3 mac-changer.py
available mac addresses
Ethernet:
ether 08:00:27:e4:af:4d txqueuelen 1000 (Ethernet)
Wlan:0
ether fe:0e:b9:ea:08:aa txqueuelen 1000 (Ethernet)
type w for wlan and e for ethernet
which interface would you like to change > w
wlan0
new MAC address > 11:22:33:44:55:66
[+] changing wlan0 MAC address to 11:22:33:44:55:66
line1
[sudo] password for kali:
line2
SIOCSIFHWADDR: Operation not permitted
line3
wlan0 changed to 11:22:33:44:55:66
ether 08:00:27:e4:af:4d txqueuelen 1000 (Ethernet)
ether b2:cc:49:8c:12:ce txqueuelen 1000 (Ethernet)
Ethernet:
ether 08:00:27:e4:af:4d txqueuelen 1000 (Ethernet)
Wlan:0
ether b2:cc:49:8c:12:ce txqueuelen 1000 (Ethernet)
thanks a lot
first, does anyone know if there is a python question website like this one, please?
I am trying to learn how to automate Kali with python
my first course is a mac changer
for running the code I need sudo privilege, so I run my code with sudo and have sudo before the code in the script
I always get the same error which is sudo related
SIOCSIFFLAGS: Operation not permitted
which occurs after print(line2) in this code
when i run it without sudo, it askes for password but again i get the same error
Can anyone help me with this please?
code:
#!/usr/bin/python
import subprocess
print("available mac addresses")
print("Ethernet:")
subprocess.call("ifconfig | grep -m1 ether", shell=True)
print("Wlan:0")
subprocess.call("ifconfig | grep ether | tail -1", shell=True)
interface = input("""type w for wlan and e for ethernet
which interface would you like to change > """)
if interface == "w":
interface = "wlan0"
elif interface == "e":
interface = "eth0"
print(interface)
mac = input("new MAC address > ")
print(f"[+] changing {interface} MAC address to {mac}")
print("line1")
subprocess.call(["sudo", "ifconfig", interface, "down"])
print("line2")
subprocess.call(["sudo", "ifconfig", interface, "hw", "ether", mac])
print("line3")
subprocess.call(["sudo", "ifconfig", interface, "up"])
print(f"{interface} changed to {mac}")
subprocess.call("ifconfig | grep ether ", shell=True)
print("Ethernet:")
subprocess.call("ifconfig | grep -m1 ether", shell=True)
print("Wlan:0")
subprocess.call("ifconfig | grep ether | tail -1", shell=True)
output:
(kaliKali)-[~/PycharmProjects/pythonProject/WORK]
$ python3 mac-changer.py
available mac addresses
Ethernet:
ether 08:00:27:e4:af:4d txqueuelen 1000 (Ethernet)
Wlan:0
ether fe:0e:b9:ea:08:aa txqueuelen 1000 (Ethernet)
type w for wlan and e for ethernet
which interface would you like to change > w
wlan0
new MAC address > 11:22:33:44:55:66
[+] changing wlan0 MAC address to 11:22:33:44:55:66
line1
[sudo] password for kali:
line2
SIOCSIFHWADDR: Operation not permitted
line3
wlan0 changed to 11:22:33:44:55:66
ether 08:00:27:e4:af:4d txqueuelen 1000 (Ethernet)
ether b2:cc:49:8c:12:ce txqueuelen 1000 (Ethernet)
Ethernet:
ether 08:00:27:e4:af:4d txqueuelen 1000 (Ethernet)
Wlan:0
ether b2:cc:49:8c:12:ce txqueuelen 1000 (Ethernet)
thanks a lot