简体   繁体   English

如何在python中更改IP地址时对其进行可视化?

[英]How to visualize IP addresses as they change in python?

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. 我编写了一个小脚本,每次打开新的终端窗口时都会收集我的外部IP地址,并将其以及当前时间附加到文本文件中。 I'm looking for ideas on a way to visualize when/how often my IP address changes. 我正在寻找一种想法来可视化我的IP地址更改的时间/频率。 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. 我经常使用matplotlib。 Any ideas? 有任何想法吗?

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). 在xkcd互联网地图上将您的IP绘制为点(或放大一些地图子集,以更好地显示不同但紧邻的IP)。

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. 按照您拥有该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. 对于“多久一次”,将标准的时间与频率的2d(条形)图划分为每天/每周/每月的存储桶将是一种标准的处理方式。 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? 在水平轴上有时间的条形图怎么样?条形图的宽度是计算机拥有特定IP地址的时间长度,条形图的高度与宽度成反比? 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. 您还可以将数据解释为脉冲密度调制信号,就像在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. 由于IP更改事件没有明显的时间长度,因此脉冲长度将是可调参数。 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. 沿着类似的线条,您可以将数据视为方波(三角波,锯齿波及c),其中每个IP更改事件都是一个电平转换。 Sounds like a fun Pure Data project. 听起来像是一个有趣的Pure Data项目。

There's a section in the matplotlib user guide about drawing bars on a chart to represent ranges. matplotlib用户指南中有一节专门介绍图表上的绘制条以表示范围。 I've never done that myself but it seems appropriate for what you're looking for. 我自己从来没有做过,但它似乎适合您的需求。

Assuming you specified terminal, i'll assume you are on a UNIX variant system. 假设您指定了终端,我将假设您在UNIX变体系统上。 Using the -f switch along with the command line utility tail can allow you to constantly monitor the end of a file. 将-f开关与命令行实用程序tail一起使用,可以使您不断监视文件的结尾。 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). 您还可以使用诸如IBM的inotify之类的东西,它可以监视文件更改或进行通知(并将文件放置在其自己的目录中),这通常在大多数发行版中都是标准的(然后可以调用tail -n 1来获取最后一行)。 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. 一旦更改了该行,就可以使用Python的time.time()获取自纪元以来的当前系统时间,并从上次更改的时间中减去该时间,然后使用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. 1 Bar的更改间隔少于1小时,另一bar的更改间隔为1-5小时,依此类推。

There is a Python implementation of tail -f located here if you don't want to use it directly. 如果您不想直接使用它,可以在此处找到 tail -f的Python实现。 Upon a detection of a change in the file, you could perform the above. 检测到文件中的更改后,可以执行上述操作。

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

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