log incoming ip/porrt connections

Irmen de Jong irmen.NOSPAM at xs4all.nl
Sat Aug 17 18:43:40 EDT 2013


On 17-8-2013 22:23, D. Xenakis wrote:
> Hi there. I have a script-service running on a remote server, listening on a specific port. What i need here is to make this also maintain a log file of ALL incoming connections.
> 
> Could someone suggest to me a simple codefunction example to implement that on my main running service?
> 
> THX!!
> 

One approach could be simply to log the client socket's peername to a logfile, something
like this:

import logging
log=logging.getLogger("connections")

...
if <<new connection>>:
  clientsocket = ...
  log.debug("new connection from "+clientsocket.getpeername())
  ...



Irmen




More information about the Python-list mailing list