Reputation: 797
>>import socket
>>s=socket.socket() //creates a TCP socket of address family; internet appications IPv4
>>s.bind(("0.0.0.0",8888))
>>s.listen(2)
>>client,addr=s.accept()
How can I find out the number of IPs trying to connect to the socket I created?
Upvotes: 0
Views: 961
Reputation: 1
You can always have a counter and it will be incremented by one, on every connection received.
connectionCounter = 0
while True:
connectionCounter += 1
c, addr = s.accept()
print 'Connection number: ' + str(connectionCounter)
c.send('Thank you for your connecting')
c.close()
I am adding a video link below to demonstrate the same. I hope it helps.
Demonstration of the above code
By using curl I am making connection request to the server.
Upvotes: 0
Reputation: 797
while True:
c, addr = s.accept()
print 'Got connection from', addr
c.send('Thank you for your connecting')
c.close()
this will indicate the connections initiated!
Upvotes: 1
Reputation: 553
You can try to use the netstat
command to check the network connections. Can't find a way to do this in pure python code.
Upvotes: 0