python报告使用中的套接字,netstat和其他人声称没有

RHES3盒子有一个奇怪的套接字问题:

Python 2.4.1 (#1, Jul 5 2005, 19:17:11) [GCC 3.2.3 20030502 (Red Hat Linux 3.2.3-52)] Type "help", "copyright", "credits" or "license" for more information. >>> import socket >>> s = socket.socket() >>> s.bind(('localhost',12351)) Traceback (most recent call last): File "<stdin>", line 1, in ? File "<string>", line 1, in bind socket.error: (98, 'Address already in use') 

这看起来很正常,让我们看看有什么套接字:

 # netstat -untap | grep 12351 

{没有输出}

 # grep 12351 /proc/net/tcp 

{没有输出}

 # lsof | grep 12351 

{没有输出}

 # fuser -n tcp 12351 

{没有输出,重复pythontesting再次失败}

 # nc localhost 12351 

{没有输出}

 # nmap localhost 12351 

{显示端口closures}

其他高端港口工作正常(如12352作品)

这个港口有什么魔力吗? 有什么地方可以看吗? python在哪里发现那个netstat不知道的socket? 任何其他方式,我可以找出什么/如果该套接字是?

不知道我是否有同样的问题,但我会把我在这里find的。

我有一个绑定到8081的python服务器进程,Apache使用反向代理模块代理它。

看着ps显示进程正在运行:

 UID PID PPID C STIME TTY TIME CMD xxxx 31896 31681 2 08:51 ? 00:00:03 \_ python /opt/xxxx/install/xxxx/xxxx/bin/content_server.py localhost:8081 

Telnet工作正常:

 $ telnet localhost 8081 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. 

然而,在netstat中的端口号的grep没有显示任何绑定到该端口的东西:

 $ netstat -a | grep 8081 $ 

虽然如果你在netstat中检查进程号,你可能会看到像这样的一行:“tproxy”作为端口号:

 $ netstat -a -p | grep 31896 (Not all processes could be identified, non-owned process info will not be shown, you would have to be root to see it all.) tcp 0 0 MELLAGFIN01:tproxy *:* LISTEN 31896/python 

其他人可以确认,但我假设这是某种内核级别的TCP代理?

如果别的东西可以绑定这个套接字,那么在两者上运行strace,并在bind()不同之前查看系统是否调用。

我认为你的脚本可能会执行多个socket.bind()调用。

在这种情况下,您在第二个调用中有“已经使用的地址”问题,但是当程序崩溃后,您将看不到打开的套接字。