在 *Nix 环境中提取至少 3 个会话的 IP 地址
如图所示,我们有一个 IP 地址列表(请注意,128.3.* 和 131.243.*)位于我们的子网内。我们更喜欢用 Perl 来做,任何其他好的想法在 *nix 环境中都更受欢迎。
图片格式如下:
目标 IP(已排序)- Dest_Port - 源IP- Source_Port
空间用作分隔符。
我们是手动完成的,但知道我们有巨大的文件并且希望自动化此过程。
问题是我们需要得到 目标 IP 地址(不在我们的子网中,不是 128.3.* 和 131.243.*) 与至少 3 个不同的人进行过沟通 IP 地址(来源)在我们的子网内 (128.3.* 和 131.243.*)。
例如 117.72.15.207 与至少 3 个不同的
59.69.194.12 80 131.243.93.74 4492
59.79.35.247 80 131.243.94.123 1307
59.100.23.87 80 131.243.92.72 45577
*117.72.15.207 80 *131.243.92.10 451
*117.72.15.207 80 *131.243.92.117 21071
117.72.15.207 80 131.243.92.117 21072
117.72.15.207 80 131.243.92.117 21073
*117.72.15.207 80 *131.243.92.191 9248
输出将为:
117.72.15.207 80 131.243.92.10 451
117.72.15.207 80 131.243.92.117 21071
117.72.15.207 80 131.243.92.191 9248
如果不清楚,请发表评论。谢谢...
As seen in the picture, we have a list of IP addresses (Please note that 128.3.* and 131.243.*) are inside our subnet. We prefer to do it in Perl, any other good ideas more than welcome in *nix environment.
The pictures is formatted as:
Destination IP(sorted)- Dest_Port
- Source IP- Source_Port
space is used as a separator.
We were doing it manually but know we have huge files and want to automate this procedure.
The problem is we need to get the
destination IP addresses (not in our subnet, not 128.3.* and 131.243.*) which are
communicated with at least 3 different
IP addresses (source) inside our subnet
(128.3. * and 131.243.*) .
As an example 117.72.15.207 communicates (not subnet ip) with at least 3 different source addresses are in our subnet (131.243.92.10, 131.243.92.117 and 131.243.92.191). Please note that it communicates with 131.243.92.117 more than one with different source port addresses so it will count only one source address in output. i put a star to specify the condition.
we need the list of IP pairs who mets this condition
59.69.194.12 80 131.243.93.74 4492
59.79.35.247 80 131.243.94.123 1307
59.100.23.87 80 131.243.92.72 45577
*117.72.15.207 80 *131.243.92.10 451
*117.72.15.207 80 *131.243.92.117 21071
117.72.15.207 80 131.243.92.117 21072
117.72.15.207 80 131.243.92.117 21073
*117.72.15.207 80 *131.243.92.191 9248
The output will be:
117.72.15.207 80 131.243.92.10 451
117.72.15.207 80 131.243.92.117 21071
117.72.15.207 80 131.243.92.191 9248
Please comment if something is unclear. Thanks...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 Perl 中有几种方法可以做到这一点,但我上面发布的示例很容易解释。
首先,它读取文件的每一行(我使用的是 DATA 句柄,但它与文件的工作方式相同),然后拆分该行以获得不同的 ip、端口组合。
然后它会填充一个多级散列,除非之前已经见过这个目标 - 源 IP 组合(您创建的不同端口点)。
最后,它会排序并循环检查是否为每个目标 IP 创建了 3 个或源 IP 条目,如果是的话,则打印出该行。
这会产生输出:
这就是您所需要的。
There are a few ways to do this in perl but the sample I've posted above is simple to explain.
First it's reading each line of the file in (I'm using the DATA handle but it'll work same with file), then splitting the line to get the different ip, port combinations.
Then it populates a multi-level hash unless this destination - source ip combination has been seen before (The differing ports point you made).
Finally it sorts and loops through checking if 3 or source IP entries have been made for each destination IP printing out the line if this is true.
This results in the output:
which is what you required.