如何在 python 中可视化 IP 地址的变化?

发布于 2024-07-17 06:23:10 字数 170 浏览 8 评论 0原文

我编写了一个小脚本,每次打开新的终端窗口时都会收集我的外部 IP 地址,并将其以及当前时间附加到文本文件中。 我正在寻找一种可视化 IP 地址更改时间/频率的方法。 我在家里和校园之间来回穿梭,可以使用脚本将它们分开,但最好将它们分开可视化。

我经常使用 matplotlib。 有任何想法吗?

I've written a little script that collects my external IP address every time I open a new terminal window and appends it, at well as the current time, to a text file. I'm looking for ideas on a way to visualize when/how often my IP address changes. I bounce between home and campus and could separate them using the script, but it would be nice to visualize them separately.

I frequently use matplotlib. Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

剧终人散尽 2024-07-24 06:23:10

将您的 IP 绘制为 xkcd 互联网地图 上的一个点(或放大地图的子集,以便更好地查看显示不同但紧密相邻的 IP)。

绘制与您使用该 IP 的频率成正比的“堆叠”的每个点,并对 IP 进行着色,使较新的点更亮,较不新的点按比例变暗。

Plot your IP as a point on the xkcd internet map (or some zoomed in subset of the map, to better show different but closely neighboring IPs).

Plot each point "stacked" proportional to how often you've had that IP, and color the IPs to make more recent points brighter, less recent points proportionally darker.

雨后咖啡店 2024-07-24 06:23:10

“何时”是一维时间数据,通过时间线很好地显示出来。 在更大的时间尺度上,你可能会丢失细节,但大多数“何时”的情节都会有这个缺陷。

对于“频率”,标准的时间与频率的二维(条形)图,分为每天/每周/每月的桶,将是标准的方法。 移动平均线也可能提供信息。

您可以结合时间线和 条形图,当您放大时时间线可见 缩小时的频率显示。

水平轴上有时间的条形图怎么样,其中每个条形的宽度是计算机持有特定 IP 地址的时间长度,并且每个条形的高度与宽度成反比? 这也将给出何时与多久绘制一次的图。

您还可以将数据解释为脉冲密度调制信号,就像您得到的那样一张超级音频 CD。 您可以绘制图表,甚至聆听数据。 由于 IP 更改事件没有明显的时间长度,因此脉冲的长度将是一个可调参数。 沿着类似的思路,您可以将数据视为方波(三角波、锯齿波等),其中每个 IP 更改事件都是电平转换。 听起来像是一个有趣的纯数据项目。

"When" is one dimensional temporal data, which is well shown by a timeline. At larger timescales, you'd probably lose the details, but most any plot of "when" would have this defect.

For "How often", a standard 2d (bar) plot of time vs frequency, divided into buckets for each day/week/month, would be a standard way to go. A moving average might also be informational.

You could combine the timeline & bar plot, with the timeline visible when you're zoomed in & the frequency display when zoomed out.

How about a bar plot with time on the horizontal axis where the width of each bar is the length of time your computer held a particular IP address and the height of each bar is inversely proportional to the width? That would also give a plot of when vs how often plot.

You could also interpret the data as a pulse density modulated signal, like what you get on a SuperAudio CD. You could graph this or even listen to the data. As there's no obvious time length for an IP change event, the length of a pulse would be a tunable parameter. Along similar lines, you could view the data as a square wave (triangular wave, sawtooth &c), where each IP change event is a level transition. Sounds like a fun Pure Data project.

╄→承喏 2024-07-24 06:23:10

matplotlib 用户指南中有一节介绍了在图表上绘制条形来表示范围。 我自己从未这样做过,但它似乎适合您正在寻找的东西。

There's a section in the matplotlib user guide about drawing bars on a chart to represent ranges. I've never done that myself but it seems appropriate for what you're looking for.

予囚 2024-07-24 06:23:10

假设您指定了终端,我将假设您使用的是 UNIX 变体系统。 使用 -f 开关和命令行实用程序 tail 可以让您持续监视文件的结尾。 您还可以使用 IBM 的 inotify 之类的东西,它可以监视文件更改或 dnotify (并将文件放在它自己的目录中),这通常是大多数发行版的标准配置(然后您可以调用 tail -n 1 来获取最后一行)。 一旦线路发生变化,您可以使用 Python 的 time.time() 获取自纪元以来的当前系统时间,并从上次更改的时间中减去它,然后使用 matplotlib 绘制此差异。 我想你可以对时间进行分类
到范围内,以便您自己更容易绘制图表。 1 条表示少于 1 小时的更换间隔,另一个条表示 1 - 5 小时之间的更换,依此类推。

如果您不想使用,此处有一个 tail -f 的 Python 实现直接它。 检测到文件发生更改后,您可以执行上述操作。

Assuming you specified terminal, i'll assume you are on a UNIX variant system. Using the -f switch along with the command line utility tail can allow you to constantly monitor the end of a file. You could also use something like IBM's inotify, which can monitor file changes or dnotify (and place the file in it's own directory) which usually comes standard on most distributions (you can then call tail -n 1 to get the last line). Once the line changes, you can grab the current system time since epoch using Python's time.time() and subtract it from the time of the last change, then plot this difference using matplotlib. I assume you could categorize the times
into ranges to make the graphing easier on yourself. 1 Bar for less than 1 hour change intervals, another for changes between 1 - 5 hours, and so on.

There is a Python implementation of tail -f located here if you don't want to use it directly. Upon a detection of a change in the file, you could perform the above.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文