Python Forum
can I setup another IP for my computer while running app?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
can I setup another IP for my computer while running app?
#1
Hello,
can I run a code that will add another IP to my network card?

for example
my computer is now 10.0.0.2/24
can I make it add 192.168.1.2/24 when I start the code , and then remove it when the code exit?

Thanks,
Reply
#2
Probably. What is your OS?
Reply
#3
Yes, you can.

import subprocess


def add_ip(ip, interface):
    subprocess.run(["sudo", "ip", "address", "add", ip, "dev", interface])


# enp3s0 is Ethernet
add_ip("172.168.0.1/24", "enp3s0")
The problem here is, that sudo requires that a user enters a password.
You can modify your /etc/sudoers to allow a user the use of ip command without the requirement of a password.


On Windows, it's different. I guess there you have to use the command line tool net.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#4
using windows
but I get the idea (I though maybe there is a ready package that can handle this)
I will give it a try and see

Thank you!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How do I locate setup.py in my computer, or install the file? JaneTan 1 1,747 Aug-26-2021, 08:37 AM
Last Post: snippsat
  Can a module be executed even if the computer running it does not install it? CFYB 5 3,425 Feb-08-2020, 01:56 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020