简体   繁体   中英

Setting IP and Subnet in python

I've been doing the programming for a start up company I know to get some experience. I've been told I'll need to relay data from my original piece of software running on one computer to 8 others using ethernet. Bear in mind I haven't really done much network stuff before.

I see that I'll need the python socket module so I've learned a bit of that. I also get that I'll need a network switch hardware-wise.

What I'm unsure about is how I set up the network in the first place. I get that I can do this via Device Manager but setting all computers to the same subnet and different IP addresses. However, the idea is that people will bring their laptops to be connected, so I don't want to have to mess around with each laptop to connect it to the network. So is there a way of doing this directly in Python so that I can just write it in the program that I'll have running on each laptop?

Thanks!

You need a DHCP server and people's NIC's to retrieve their network configuration automatically.

Windows:

netsh interface ip set address "Local Area Connection" dhcp

Debian (/etc/network/interfaces):

auto eth0
iface eth0 inet dhcp

Red Hat (/etc/sysconfig/network-scripts/ifcfg-eth0):

DEVICE=eth0
BOOTPROTO=dhcp
ONBOOT=yes

I suppose you could use Python or whatever language you're convenient in to fetch the relevant interface's name, as they're not guaranteed to be named "eth0" or "Local Area Connection", eg subprocess.Popen("cat /proc/net/dev/").

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM