V
V
Vladislav Dudashvili2021-04-12 23:03:25
linux
Vladislav Dudashvili, 2021-04-12 23:03:25

What is the error in the implementation of the script to change the poppy address?

I am new to this. I'm trying to implement a regular script to change the poppy address.
On the command line, I can change it with:
sudo ifconfig eth0 down
sudo ifconfig eth0 hw ether adress
sudo ifconfig eth0 up


When I make a script, I get an error all the time. What is the problem?

SIOCSIFFLAGS: Operation not permitted
SIOCSIFHWADDR: Operation not permitted
SIOCSIFFLAGS: Operation not permitted


#!/usr/bin/env python

import subprocess

subprocess.call("ifconfig eth0  down", shell=True)
subprocess.call("ifconfig eth0 hw ether 00:11:22:33:44:66", shell=True)
subprocess.call("ifconfig eth0 up", shell=True)


ifconfig

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.0.2.15  netmask 255.255.255.0  broadcast 10.0.2.255
        inet6 fe80::a00:27ff:fea6:1f86  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:a6:1f:86  txqueuelen 1000  (Ethernet)
        RX packets 333400  bytes 497332684 (474.2 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 158722  bytes 9660948 (9.2 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 118  bytes 18510 (18.0 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 118  bytes 18510 (18.0 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

Answer the question

In order to leave comments, you need to log in

1 answer(s)
U
Uragiremono, 2021-04-22
@Uragiremono

SIOCSIFFLAGS: Operation not permitted
SIOCSIFHWADDR: Operation not permitted
SIOCSIFFLAGS: Operation not permitted

Superuser rights are required to enable/disable the interface or change the MAC address.
2 options:
1) Run the script as root, then you don't need to edit anything in the script.
2) Elevate the privileges of the user from which the script is run, you need to add sudo before the commands in subprocess.call .
#!/usr/bin/env python

import subprocess

subprocess.call("sudo ifconfig eth0  down", shell=True)
subprocess.call("sudo ifconfig eth0 hw ether 00:11:22:33:44:66", shell=True)
subprocess.call("sudo ifconfig eth0 up", shell=True)

Do not forget to allow the user to elevate privileges without entering a password, or add a check to the script:
if <password is required>
<enter password>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question