在Linux机器上获取所有连接的IP [英] Get all connected IP´s on the Linux machine

查看:344
本文介绍了在Linux机器上获取所有连接的IP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我被问到一个问题在面试,我不能做。

 在Linux机器上捕获所有连接的IP 
检查每个连接的IP TCP端口1706打开

如果其打开>执行命令。 CURL'http:// some address'
否则什么都不做。
程序将每60分钟检查一次



Plattform Linux Ubuntu服务器12. X64 / x32

C ++中的WAP



谢谢!!

解决方案

制作一个bash脚本。



LOGIC:



使用 netstat -natp 通过 awk / sed 过滤它以获取端口,然后grep it)然后使用简单测试来查看结果为空。如果是,运行 curl



简单的东西,真的。



编辑:



netstat 是一个实用程序,将显示您的计算机上的所有连接。 netstat -natp 显示计算机上有tcp套接字的程序列表。



sed awk 用于文本格式化。您可以使用它们列出特定的列。



grep 搜索输入以查找指定的字符串。 >

bash允许基本逻辑,并可用于查看字符串是否为空。



cron 是一个linux进程,它调度要在特定时间运行的命令。



编辑#2:



您可以轮询 / proc / net / tcp ,但由于 netstat 很好,为什么麻烦?


Recently i was asked a question in an interview which i couldn't do. Anyone got a solution for this?

Grab all connected IP´s on the Linux machine
check every connected IP if TCP port 1706 is open

if its open > execute command.  CURL ‘http:// some address ’ 
Else do nothing.
program will check this every 60 minits



Plattform Linux Ubuntu Server 12. X64 / x32

WAP in C++

Thanks!!

解决方案

Make a bash script.

LOGIC:

Use netstat -natp (filter it through awk/sed to get the ports, then grep it) Then use a simple test to see if the result was empty. Run curl if it was.

Put this in a cron job. Simple stuff, really.

EDIT:

netstat is a utility which will show you all of the connections on your computer. netstat -natp shows a list of the programs which have tcp sockets on your computer.

sed and awk are used for text formatting. You can use them to list a specific column.

grep searches input to find a specified string.

bash allows for basic logic, and can be used to see if a string is empty.

cron is a linux process which schedules commands to be run at certain times.

EDIT #2:

You COULD poll /proc/net/tcp, but since netstat does that and formats it nicely, why bother?

这篇关于在Linux机器上获取所有连接的IP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆