标签:class 建立 author lease 地址 read article socket date
/*********************************************************************
* Author : Samson
* Date : 11/19/2014
* Test platform:
* 3.13.0-24-generic
* GNU bash, 4.3.11(1)-release
* *******************************************************************/
主要分为下面几个步骤:
(1)、通过使用抓包Libpcap库技术,对网络流量包进行获取。从而能够得到每一个网络通信包的五元组(源地址、目标地址、源port、目标port、协议号)信息和当前包的流量大小。得到这些信息后建立一个表,此表中的同一会话的包大小信息会随着此会话的不断交互而累加数据包的大小。
(2)、通过对/proc/下的全部进程的fd/文件夹下的全部链接进行遍历查看link的值。将遍历到的全部包括socket:开头的连接,将进程号与遍历所得的相应进程号、进程相应的全部socket fd相应的inode号进行建表。在命令行能够输入下面命令进行某一进程的当前网络连接情况查看,例如以下(以firefox为例):
#get PID of firefox
v0id@v0id:~$ ll /proc/2143/fd/ | grep socket ; cat /proc/net/tcp
sl local_address rem_address st tx_queue rx_queue tr tm->when retrnsmt uid timeout inode
0: 0101007F:0035 00000000:0000 0A 00000000:00000000 00:00000000 00000000 0 0 12396 1 00000000 100 0 0 10 0
1: 0100007F:0277 00000000:0000 0A 00000000:00000000 00:00000000 00000000 0 0 11404 1 00000000 100 0 0 10 0
2: 9707A8C0:8BB9 0C7CB5DC:0050 02 00000001:00000000 01:00000166 00000002 1000 0 5243074 2 00000000 400 0 0 2 5
3: 9707A8C0:86F7 DF08A8C0:0050 01 00000000:00000000 00:00000000 00000000 1000 0 5245647 1 00000000 21 4 8 10 -1
4: 9707A8C0:BFC9 E99D4F75:0050 01 00000000:00000000 00:00000000 00000000 1000 0 5248217 1 00000000 20 4 24 10 -1
5: 9707A8C0:85FC AE2ED0CB:0050 01 00000000:00000000 00:00000000 00000000 1000 0 5248218 2 00000000 20 4 24 10 -1
6: 9707A8C0:9052 C99D4F75:0050 01 00000000:00000000 00:00000000 00000000 1000 0 5246239 2 00000000 20 4 20 10 -1
7: 9707A8C0:9281 925C4F75:0050 01 00000000:00000000 00:00000000 00000000 1000 0 5246331 1 00000000 20 4 8 10 -1
8: 9707A8C0:DFB3 DD5D4F75:0050 01 00000000:00000000 00:00000000 00000000 1000 0 5249212 2 00000000 21 4 24 10 -1
9: 9707A8C0:DFB5 DD5D4F75:0050 01 00000000:00000000 00:00000000 00000000 1000 0 5248223 2 00000000 20 4 24 10 -1
10: 9707A8C0:A614 E19D4F75:0050 01 00000000:00000000 00:00000000 00000000 1000 0 5246330 1 00000000 20 4 24 10 -1
11: 9707A8C0:9051 C99D4F75:0050 01 00000000:00000000 00:00000000 00000000 1000 0 5248189 2 00000000 20 4 1 6 -1
12: 9707A8C0:904B C99D4F75:0050 01 00000000:00000000 00:00000000 00000000 1000 0 5244897 1 00000000 20 4 8 10 -1
13: 9707A8C0:DFA5 DD5D4F75:0050 01 00000000:00000000 00:00000000 00000000 1000 0 5248187 2 00000000 20 4 8 10 -1
14: 9707A8C0:A613 E19D4F75:0050 01 00000000:00000000 00:00000000 00000000 1000 0 5248214 1 00000000 20 4 24 10 -1
15: 9707A8C0:905E C99D4F75:0050 01 00000000:00000000 00:00000000 00000000 1000 0 5249281 3 00000000 20 5 3 10 -1
16: 9707A8C0:EAFE DF08A8C0:0050 08 00000000:00000001 00:00000000 00000000 1000 0 2102209 1 00000000 20 4 6 50 16
17: 9707A8C0:DFB0 DD5D4F75:0050 01 00000000:00000000 00:00000000 00000000 1000 0 5248216 2 00000000 20 4 24 10 -1
18: 9707A8C0:904E C99D4F75:0050 01 00000000:00000000 00:00000000 00000000 1000 0 5246227 2 00000000 20 4 20 10 -1
19: 9707A8C0:DFB6 DD5D4F75:0050 01 00000000:00000000 00:00000000 00000000 1000 0 5249279 2 00000000 21 0 0 10 -1
20: 9707A8C0:905F C99D4F75:0050 01 00000000:00000000 00:00000000 00000000 1000 0 5249282 2 00000000 20 4 9 10 -1
21: 9707A8C0:C8CF 8805E29F:0050 08 00000000:00000001 00:00000000 00000000 1000 0 273820 1 00000000 20 4 6 43 16
22: 9707A8C0:975D 525D58DE:0050 01 00000000:00000000 00:00000000 00000000 1000 0 5246226 1 00000000 21 4 24 10 -1
23: 9707A8C0:9055 C99D4F75:0050 01 00000000:00000000 00:00000000 00000000 1000 0 5248215 1 00000000 20 4 20 10 -1
24: 9707A8C0:DFB4 DD5D4F75:0050 01 00000000:00000000 00:00000000 00000000 1000 0 5248222 2 00000000 20 4 24 10 -1
25: 9707A8C0:DFA9 DD5D4F75:0050 01 00000000:00000000 00:00000000 00000000 1000 0 5248188 2 00000000 21 4 8 10 -1
26: 9707A8C0:904F C99D4F75:0050 01 00000000:00000000 00:00000000 00000000 1000 0 5246228 2 00000000 20 4 11 10 -1
能够在发上的内容中找到inode号与(2)中列出的socket:[inode]一样的值了吧,比如inode为5248222的连接,同样的即是说这个连接是属于firefox进行的了。
标签:class 建立 author lease 地址 read article socket date
原文地址:http://www.cnblogs.com/liguangsunls/p/7224694.html