简体   繁体   English

Python 中的虚拟网络接口

[英]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.通过将 web 浏览器指向http://192.168.192.168/并提交表单来配置打印机。 I wrote a Python script that can simulate a form POST, and the printers can now be configured without using the web interface.我写了一个 Python 脚本,可以模拟表单 POST,现在可以在不使用 web 接口的情况下配置打印机。 The one drawback is that my computer must be on the 192.168.192.0/24 network.一个缺点是我的电脑必须在 192.168.192.0/24 网络上。

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?是否可以在 Python 中创建我的脚本可以使用的虚拟网络接口,而无需我手动更改计算机网络设置?

You have a problem that python cannot solve.您有一个 python 无法解决的问题。

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;如果 192.168.192.0 出于管理/安全原因没有被有意分割; it could be a simple oversight by your LAN administrator.这可能是您的 LAN 管理员的简单疏忽。 In that case, they can add 192.168.192.0 to the corporate routing table.在这种情况下,他们可以将 192.168.192.0 添加到公司路由表中。

The final option would be some kind of VPN connectivity between the administrative domains... again, discuss with your network admins.最后的选择是管理域之间的某种 VPN 连接......再次与您的网络管理员讨论。

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由于您需要 linux 以太网别名,因此最简单的方法是在 linux 中使用iproute2 ... 使用ip addr add 192.168.192.1/24 dev eth0作为根地址添加 192.1608.192。

[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)现在将您的打印机插入以太网交换机...您应该能够 ping 192.168.192.168... 以删除: ip addr del 192.168.192.1/24 dev eth0 (以 root 身份)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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