python reports socket in use, netstat and others claim its not

Posted by captainmish on Server Fault See other posts from Server Fault or by captainmish
Published on 2012-02-24T14:13:13Z Indexed on 2012/07/07 9:18 UTC
Read the original article Hit count: 281

Filed under:
|
|
|

We have a strange socket issue with a RHES3 box:

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')

This seems normal, lets see what has that socket:

# netstat -untap | grep 12351

{no output}

# grep 12351 /proc/net/tcp

{no output}

# lsof | grep 12351

{no output}

# fuser -n tcp 12351

{no output, repeating the python test fails again}

# nc localhost 12351

{no output}

# nmap localhost 12351

{shows port closed}

Other high ports work fine (eg 12352 works)

Is there something magic about this port? Is there somewhere else I can look? Where does python find out that socket is in use that netstat doesnt know about? Any other way I can find out what/if that socket is?

© Server Fault or respective owner

Related posts about networking

Related posts about tcp