我应该使用 Perl 还是 Python 进行网络监控?
我想在网络方面完成一些工作,对 LAN 上的众多计算机进行 ping 操作并检索有关响应时间的数据。 Perl 和 Python 哪个最有用、最高效?
I want to have some work done on the Network front, pinging numerous computers on a LAN and retrieving data about the response time. Which would be the most useful and productive to work with: Perl or Python?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
任何一个都应该工作得很好。 如果您没有这方面的经验,请抛硬币。 没有一种语言天生具有生产力; 语言使人们变得富有成效。 不同的人从不同的语言中受益不同。
不过,总的来说,当您知道自己的具体任务并需要选择工具时,请寻找可以让您的生活变得轻松的库。 对于 Perl,请查看综合 Perl 存档网络。 这里有适合您可能需要的所有网络事物的模块。
Python 可能有非常相似的工具和库; 我只是不知道它们是什么。
Either one should work just fine. If you don't have experience with either, flip a coin. No language is inherently productive; languages allow people to be productive. Different people will benefit differently from different languages.
In general, though, when you know your specific task and need to choose a tool, look for the libraries that would make your life easy. For Perl, check out the Comprehensive Perl Archive Network. There are modules for just every networking thing you might need.
Python probably has very similar tools and libraries; I just don't know what they are.
我比 Python 更了解 Perl,所以我的选择落在 Perl 上。 也就是说,我认为在低级别任务上(例如对网络上的计算机执行 ping 操作等),它们是相当等效的。 Python 可能有更好的面向对象支持,但对于脚本编写(这恰好是您所需要的),Perl 的威力是相当明显的。 您在 CPAN 上找到的大量经过测试的模块(其中一些甚至是面向对象的)通常可以完成所有任务如果您使用得当,它们甚至可以很好地扩展。
I know Perl better than Python, so my choice would fall on Perl. That said, I'd argue that on low level tasks (like pinging computers on a network and things like that) they are rather equivalent. Python may have a better object-oriented support but for scripting (that happens to be what you need) the power of Perl is quite obvious. The large pool of tested modules (some of them are even object oriented) that you find on CPAN usually can do everything you need and they can even scale well if you use them appropriately.
我不懂Python,所以我无法评论它提供的功能,并且我同意那些建议使用Nagios 或其他现有系统的人。
但是,如果您决定使用 Perl 构建自己的系统,请考虑使用 POE。 POE 是一个协作式多任务处理和网络框架。
POE 的学习曲线很陡。 但你的努力很快就会得到回报。 POE 将为构建提供坚实的基础。 您需要的大部分客户端代码已经可以在CPAN。
I don't know Python, so I can't comment on what it offers, and I agree with those who suggest Nagios or other existing systems.
However, if you decide to roll your own system with Perl, Consider using POE. POE is a cooperative multitasking and networking framework.
POE has a steep learning curve. But you will be repaid for you effort very quickly. POE will provide a solid foundation to build from. Much of the client code you will need is already available on CPAN.
无论您更了解或更习惯使用哪个。 他们都可以胜任这项工作并且做得很好,所以这是你的偏好。
Whichever you know better or are more comfortable using. They both can do the job and do it well, so it is your preference.
现在,我已经尝试了使用各种 TAP 库(主要是 bash+netcat+curl 和 perl)为网络服务创建一些简单的单元测试的方法。 优点是您编写了一个可用于单元测试和网络测试的脚本。
显示是通过 TAP::Harness::HTML 进行的。
Right now I've experimented the approach of creating some simple unit test for network services using various TAP libraries (mainly bash+netcat+curl and perl). The advantage is that you wrote a single script that you can use for both unit and network testing.
The display is dove via TAP::Harness::HTML.
我想说,如果您需要一些快速而肮脏的东西,并且要在今天下午之前启动并运行,那么 Perl 可能是更好的语言。
然而,为了开发易于维护和扩展并且可以随着时间的推移而构建的可靠应用程序,我会选择 python。
当然,这是假设您对两种语言的了解程度相同。
I'd say that if you need something quick and dirty that's up and running by this afternoon, then perl is probably the better language.
However for developing solid application that's easy to maintain and extend and that you can build on over time, I'd go with python.
This is of course assuming you know both languages more or less equally well.
我同意你使用哪种编程语言是相当主观的 - 本质上我宁愿尽可能快速有效地完成工作,从而使其可支持 - 所以这取决于你的基础设施......
我可以建议你看看 Nagios 而不是自己重新发明轮子?
虽然 Nagios 在配置方面可能需要更大的学习曲线,但从长远来看这是值得的,如果您找不到适合您要求的插件,那么很容易编写自己的插件。 Joel Spolsky 就此写了一篇有趣的文章。
I agree that it is pretty subjective which programming language you use - essentially I would rather get the job done as quickly and efficiently as possible which making it supportable - so that depends on your infrastructure...
Can I suggest that you look at Nagios rather than re-inventing the wheel yourself?
While Nagios might require a greater learning curve in terms of configuration, it will be worth it in the long run, and if you can't find a plugin to suit your requirements, then it is easy to write your own. Joel Spolsky has written an interesting article on this.
嗯,我同时使用 Perl 和 Python,我的日常工作是支持网络监控软件。 大多数要点已经涵盖,但我将在这里巩固/重申:
不要重新发明轮子 - 有数十种网络监控解决方案可用于执行 ping 测试和分析收集的数据。 参见示例
如果您坚持自己做这件事,可以使用 Perl 或 Python 来完成 - 使用您最了解的。 如果您计划解析大量文本,那么在 Perl 中执行此操作将比在 Python 中更容易。 两者都可以做到这一点,但 Python 需要 OOP 方法,而且它不像 Perl 的内联正则表达式语法那么简单。
使用库 - 在你之前很多很多人都已经完成了这项任务,因此请四处寻找合适的库,例如 Perl 中的 Net::Ping 或 Python 中的 icmplib 或 这个 ping.py< /a> 代码。
使用线程或异步 ping - 否则 ping 将永远持续,例如参见 此秘籍 使用线程同时运行 ping。 使用任一方法在 Python 中都特别容易做到这一点,因此在 IMO 中,Python 比使用 Perl 更容易使用。
Well, I work in both Perl and Python, and my day job is supporting a network monitoring software. Most of the import points have already been covered, but I'll consolidate/reiterate here:
Don't reinvent the wheel - there are dozens of network monitoring solutions that you can use to perform ping tests and analyze collected data. See for example
If you insist on doing this yourself, this can be done in either Perl or Python - use the one you know best. If you're planning on parsing a lot of text, it will be easier to do this "quick and dirty" in Perl than it will be in Python. Both can do it, but Python requires an OOP approach and it just isn't as easy as Perl's inline regex syntax.
Use libraries - many, many people have done this task before you so look around for a suitable lib like Net::Ping in Perl or the icmplib in Python or this ping.py code.
Use threads or asynchronous pings - otherwise pinging is going to take forever for example see this recipe using threads to run pings simultaneously. This is particularly easy to do in Python using either approach, so this is one place Python will be easier to work with IMO than using Perl.
和 Perl 一起去吧。
您将可以访问一个不错的 Ping 对象 Net::Ping 并存储数据库中的结果非常容易。
Go with Perl.
You'll have access to a nice Ping object, Net::Ping and storing the results in a database is pretty easy.