jaraco / irc

Full-featured Python IRC library for Python.
MIT License
390 stars 85 forks source link

dcc_listen with port selection #112

Closed LoucIsZbib closed 7 years ago

LoucIsZbib commented 7 years ago

Hello, I'm using your irc lib from a while now and it is awsome, thanks for your work and sharing it !

I would like to be able to select the port for dcc_listen connection, I think the modification needed are the following ones :

In client.py

line 1046 : class DCCConnection: def listen(self): ==> def listen(self, PORT=0):

line 1061: self.socket.bind((socket.gethostbyname(socket.gethostname()), 0)) ==> self.socket.bind((socket.gethostbyname(socket.gethostname()), PORT))

line 1237: def dcc_listen(self, dcctype="chat"): ==> def dcc_listen(self, dcctype="chat", PORT=0):

line 1244: dcc.listen() ==> dcc.listen(PORT)

It would help me if you can integrate these modifications (which shouldn't have consequences for people using the actual version of irc module), so I can select port with dcc_listen(PORT) directly with module installed by "pip install irc"

Luc

igel-kun commented 7 years ago

oh, while we're at it, it would also be cool to be able to choose the interface/address on which the socket should be opened. Indeed on my test machine (debian linux), self.socket.bind((socket.gethostbyname(socket.gethostname()), 0)) opens a socket on 127.0.1.1: which is not sensible for anyone outside my localhost. Is it somehow possible to reuse the IP of the server connection of the parent as default?

cheers

jaraco commented 7 years ago

it would also be cool to be able to choose the interface/address on which the socket should be opened

I agree. Probably it would be best to bind to '0.0.0.0' or '::'.

For comparison, on my machine, the routine returns my machine's assigned IP:

>>> socket.gethostbyname(socket.gethostname())
'192.168.99.99'
jaraco commented 7 years ago

Putting these two requests together, the DCC listen should probably accept a bind_addr parameter, which is the host pair (or quad) as passed to socket.bind.

jaraco commented 7 years ago

So yes, I'd support a PR to address this need. Sorry for the long delay in responding.

jaraco commented 7 years ago

Closing as languishing, but I welcome a pull request.