Page 1 of 1
own IP address?
Posted: Fri Jun 05, 2020 7:33 pm
by jcw
I need to report "my" IP address to a connected client. The server is bound to interface "0.0.0.0", i.e. any.
The socket.accept() call returns the address of the other end, i.e. the client's IP address.
In general, "my" IP address is ill-defined, i.e. there can be more than one interface.
But once there is a connection, is there is some way to find out which interface it's bound to?
Re: own IP address?
Posted: Fri Jun 05, 2020 8:42 pm
by Roberthh
wlan.ifconfig()?
Re: own IP address?
Posted: Fri Jun 05, 2020 8:59 pm
by jcw
Whee, could it be that simple? Not sure - I'm trying this on unix, there's no network module, is there?
UPDATE: Aha, the IP address is not needed after all (I am writing a little FTP server, but PASV also works with a "0.0.0.0" reply).
Re: own IP address?
Posted: Sat Jun 06, 2020 5:41 am
by Roberthh
If you want to look at another implementation for comparison, you may look here:
https://github.com/robert-hh/FTP-Server ... 2-and-PYBD, file ftp.py. It is based on work from Christopher Popp and Paul Sokolovsky.
Re: own IP address?
Posted: Sat Jun 06, 2020 7:45 am
by jcw
Hey, thanks ... nice! Now I see where your ifconfig suggestion comes from.
FWIW, my freshly brewed implementation is here:
https://git.jeelabs.org/jcw/pythonx/src ... master/ftp
It uses uasyncio to avoid blocking on new clients connecting and on waiting for a new command.
It also turns out to be very slow ... I suspect due to the underlying blocking flash file system I/O.
Re: own IP address?
Posted: Sat Jun 06, 2020 11:32 am
by Roberthh
Very elegant and concise code.
Re: own IP address?
Posted: Sat Jun 06, 2020 12:52 pm
by kevinkk525
looks nice. Might even consider using it myself if it was published on github so I can make it a submodule in my project.
So far Robert's callback driven ftp server has served me well on the esp32.
Re: own IP address?
Posted: Mon Jun 08, 2020 11:40 am
by jcw
Thanks. Kevin, it's very easy to integrate any git repository into your own setup, e.g.
Code: Select all
git submodule add https://git.jeelabs.org/jcw/pythonx jcw-pythonx
Perhaps not widely known due to GitHub's popularity, but git itself is a
distributed version control system.
Re: own IP address?
Posted: Mon Jun 08, 2020 3:24 pm
by kevinkk525
oh, thanks. I might try that when I continue programming.
Never tried integrating a git repository that wasn't hosted on github itself.