简体   繁体   中英

Virtual Network Interface in Python

Background:

I have to set up some Epson receipt printers. The printers are configured by pointing your web browser to http://192.168.192.168/ and submitting a form. I wrote a Python script that can simulate a form POST, and the printers can now be configured without using the web interface. The one drawback is that my computer must be on the 192.168.192.0/24 network.

Question:

Is it possible to create a virtual network interface in Python that my script can use without me having to manually change the computers network settings?

You have a problem that python cannot solve.

It sounds like your network has been administratively compartmentalized for some reason. If there is a firewall or a bastion-host machine connected to both administrative domains, you might be able to leveragePort Address Translation to keep this server on one network and poll the other.

If 192.168.192.0 has not been intentionally segmented for administrative / security reasons; it could be a simple oversight by your LAN administrator. In that case, they can add 192.168.192.0 to the corporate routing table.

The final option would be some kind of VPN connectivity between the administrative domains... again, discuss with your network admins.

EDIT

Since you need a linux ethernet alias, the easiest way is with iproute2 in linux... use ip addr add 192.168.192.1/24 dev eth0 as root

[mpenning@Finger ~]$ sudo ip addr add 192.168.192.1/24 dev eth0
[mpenning@Finger ~]$ ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
    link/ether 78:2b:cb:0a:8c:f9 brd ff:ff:ff:ff:ff:ff
    inet 192.168.12.238/24 brd 192.168.12.255 scope global eth0
    inet 192.168.192.1/24 scope global eth0
    inet6 fe80::7a2b:cbff:fe0a:8cf9/64 scope link 
       valid_lft forever preferred_lft forever
[mpenning@Finger ~]$ ip route show
192.168.192.0/24 dev eth0  proto kernel  scope link  src 192.168.192.1 
192.168.12.0/24 dev eth0  proto kernel  scope link  src 192.168.12.238 
default via 192.168.12.236 dev eth0 
[mpenning@Finger ~]$

Now plug your printer into your ethernet switch... you should be able to ping 192.168.192.168... to remove: ip addr del 192.168.192.1/24 dev eth0 (as root)

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