在接口打开时,可以扫描特定的 MAC 地址吗?
我承认Linux网络系统对我来说有些陌生,我对它足够了解,可以手动配置路由并在必要时分配静态IP。
那么简单的问题是,在 ifconfig 配置文件中,是否可以向 python 脚本添加一个 post connect 挂钩,然后使用 python 脚本在 /etc/hosts 中重新分配主机名,并在主机名确定后生成一个新进程来执行其他操作已经升级。
这对我来说是一个“有趣”的项目,可以解决我日常生活中的烦恼。 当我早上启动工作站时,DHCP 服务会随机为其分配一个 IP。 因此,我通常会停止正在做的事情,查找新 IP,将该 IP 输入到我的笔记本电脑中,然后运行协同程序,以便我可以共享两台机器。 我估计我一周每天都会花 10-15 分钟来做这件事,而且我从来没有真正搞乱过 Linux 的网络系统,所以它最终会成功。
我已经认为我的 python 脚本必须以 root 身份运行,因此我将其存储在 /root 或其他安全的地方。 我在堆栈溢出上发现了一个类似的问题,它为我指明了 http://www 的方向.secdev.org/projects/scapy/index.html 用于 ARP 的原始数据包工具集。 编辑主机文件很简单...只是想知道尝试将此挂钩放入核心服务可能会导致什么副作用。
I admit the linux network system is somewhat foreign to me, I know enough of it to configure routes manually and assign a static IP if necessary.
So quick question, in the ifconfig configuration files, is it possible to add a post connect hook to a python script then use a python script to reassign a hostname in /etc/hosts and spawn off a new process to do other things once the hostname has been updated.
This is a "fun" project for me to solve an annoyance in my daily routine. When I boot up my workstation in the morning, the DHCP service assigns it a IP at random. So I usually stop what I'm doing, lookup my new IP, type that IP into my laptop and get synergy running so I can share the two machines. I figure I lose 10-15 minutes a day doing this everyday of the week and I've never really messed with linux's networking system so it would ultimately pan out.
I already figured my python script would have to run as root, therefore I'd store it in /root or somewhere else that's safe. I found a similar question on stack overflow that pointed me in the direction of http://www.secdev.org/projects/scapy/index.html a raw packet toolset to work with ARP. Editing the host file is a snap... just wondering what possible side effects of trying to put this hook into a core service might cause.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
最干净的解决方案是使用 DHCP 服务器与本地 DNS 服务器交换其分配。 因此,无论您的工作站被分配到哪个 IP 地址,都可以在相同的主机名下进行访问。
这个概念用于每个成熟的 Windows 网络以及任何其他配置良好的网络。
Cleanest solution would be to have a DHCP server that exchanges its assignments with a local DNS server. So regardless which IP address your workstation is being assigned to, it is accessible under the same hostname.
This concept is used in every full-blown windows network as well as in any other well configured network.
只需确保 Avahi / Bonjour 正在运行,然后输入主机名.local(或者也尝试主机名.localdomain) - 它使用 mDNS 进行解析,因此您不必关心什么你的IP是或正在操纵/etc/hosts。
Just make sure Avahi / Bonjour's running, then type hostname.local (or also try hostname.localdomain) - it resolves using mDNS, so you don't have to care what your IP is or rigging /etc/hosts.
抱歉,这看起来像是试图在不存在问题的情况下创建一个问题,然后使用有点疯狂的方法来解决它。 :)
您可以将 dhcp 服务器(路由器)配置为始终为您的工作站发出固定 IP。 如果您没有 dhcp 服务器,那么为什么要使用 dhcp 来配置接口呢? 更改配置(Ubuntu 和 Debian 中的
/etc/network/interfaces
)以将静态 IP 地址分配给接口。Sorry, it looks like an attempt to create a problem where no problem exists, and subsequently solve it using a bit crazy methods. :)
You can configure your dhcp server (router) to always issue a fixed ip for your workstation. If you don't have dhcp server, then why do you use dhcp for configuring the interface? Change the configuration (
/etc/network/interfaces
in Ubuntu and Debian) to assign static ip address to the interface.您还可以使用 arp-scan (存在同名的 Debian 软件包,不确定其他发行版是否如此)来扫描整个网络。 让脚本解析其输出,然后一切就准备好了。
You could also use arp-scan (a Debian package of the name exists, not sure about other distributions) to scan your whole network. Have a script parse its output and you'll be all set.