작성일 댓글 남기기

Python, listen 된 port 의 process name 구하기

python, listen port, inode, pid, process name

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/local/bin/python
import glob
import os
import commands
 
net = commands.getoutput("grep ' 0A ' /proc/net/tcp")
if os.path.exists('/proc/net/tcp6'):
    net6 = commands.getoutput("grep ' 0A ' /proc/net/tcp6")
    if net6:
        net += '\n'
        net += net6
 
inode2port = dict() # {inode:port}
lines = net.splitlines()
for line in lines:
    buf = line.split()
    inode2port[long(buf[9])] = int(buf[1].split(":")[1],16)
 
port2pname = {} # {port:process name}
fdlist = glob.glob('/proc/*/fd/*')
for fd in fdlist:
    try:
        pid = fd.split('/')[2]
        inode = long(os.stat(fd)[1])
        if inode in inode2port:
            pname = commands.getoutput('cat /proc/%s/status | grep Name' % pid).split()[1]
            port2pname[inode2port[inode]] = pname
    except:
        pass
 
print port2pname
작성일 댓글 2개

hyunsu.com 의 db를 MariaDB로 변경.

DB를 기존에 MySQL-5.1.19 쓰고 있었는데 MariaDB-5.5.29로 변경했다.

페도라와 수세가 MariaDB로 갈아탄다는 얘기가 있고,
여기저기서 MySQL의 미래에 대한 비관적인 시각을 가지고 있는 듯 하다.
내 생각에는 페도라가 MariaDB로 정말 갈아타면 판세는 확 바뀔 것 같다.
난 오늘 미리 갈아탄다.
누구도 들어오지 않는 이 블로그의 디비를 바꾸는게 사실 아무 의미 없긴 하지만… 흑흑