socket programming and port scans

R

rbt

I don't fully understand sockets, I just know enough to be dangerous.
The below is not detected by nmap, but is affected by iptables or ipsec.
Can anyone explain why that is?

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((ip_param, port_param))
while 1:
s.listen(5)

I can connect to the socket server and even transmit data so I know it's
there.

Thanks,
rbt
 
M

millerch

Are you explicitly referencing the port for nmap, or is it a general
port scan?

The version of nmap I run only checks common ports unless a port range
is specified.
 
R

rbt

millerch said:
Are you explicitly referencing the port for nmap, or is it a general
port scan?

The version of nmap I run only checks common ports unless a port range
is specified.

I did not know that. It works as expected now. Thanks!
 
P

Peter Hansen

rbt said:
I don't fully understand sockets, I just know enough to be dangerous.
The below is not detected by nmap, but is affected by iptables or ipsec.
Can anyone explain why that is?

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((ip_param, port_param))
while 1:
s.listen(5)

This, by the way, is wrong. s.listen(5) just tells the stack that you
would like to allow a backlog of up to 5 waiting-to-be-connected
connection attempts while you are accepting another. The call doesn't
block and needn't be called repeatedly. You could just as well do the
call to listen first, then have an empty "while 1: pass" loop (but note
that in either case it is a "busy wait", consuming 100% CPU while it runs).

What you are looking for is more like this:

s.listen(5)
while 1:
s.accept() # wait for connection, and ignore it


If you want to simulate a little server to allow multiple connections,
you would of course need to use the value returned by accept() and
probably call close() on the client socket right away.

-Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

socket programming 8
listening socket 3
socket data sending problem 2
Java socket programming 1
Socket error 98 "Address already in use" 5
python socket query 4
Pickling over a socket 13
Socket Performance 14

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top