English 中文(简体)
output output
原标题:parsing ss output with awk
  • 时间:2012-01-13 18:05:38
  •  标签:
  • awk
  • netstat

I want to get a list of applications and their output ports for some given list of applications, from my C program.

我不想使用类似东西。

ss -natp |  awk  /firefox/ { split($4,array,":"); printf "%d ", array[2]} END{print ""}  

名单见41477 59505

What s an efficient way of calling ss once and then getting such this for all the applications? (Multiple output pipes? Is there an optimal way to use awk for many matches? Catting ss to a file and then awk-ing many it many times?)

感谢!

最佳回答

使用<代码>wk的关联阵列能力。

ss -natp | awk  {port = split($4, array, ":"); program[$1] = program[$1] " " port; }
                END { for (p in program) print p ": " program[p]; } 

未经测试,但这一概念大致正确。

问题回答

暂无回答




相关问题
How to do like "netstat -p", but faster?

Both "netstat -p" and "lsof -n -i -P" seems to readlinking all processes fd s, like stat /proc/*/fd/*. How to do it more efficiently? My program wants to know what process is connecting to it. ...

How do I access netstat data in Python?

I m trying to need to access/parse all outgoing connections on a particular port number on a Linux machine using a Python script. The simplest implementation seems to be to open a subprocess for ...

Extract IP from netstat output

The netstat output contains thing like... tcp 0 0 0.0.0.0:80 221.126.149.99:51973 ESTABLISHED 23879/apache2 tcp 0 0 0.0.0.0:80 66.249.68.154:40883 ...

netstat command on a server (winform application)

I m looking for how to recorgnize some server (windows in my case) network configuration (information we obtain using netstat dos command). I have the login and password of the target (server), and ...

Java Connections netstat -ano

I am new to java and I have been testing my application all day long. I just did netstat -ano and it gave me a huge listing of active connections (listening, established) does this mean when i ...

Netstat -ban (or -oan) equivalent in .NET

I d like to know if a particular process is using a given port, i.e. netstat -ban. I came across using IPGlobalProperties to get the list of active connections, but this doesn t seem to include ...

热门标签