own IP address?
own IP address?
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?
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?
Jean-Claude Wippler
Re: own IP address?
wlan.ifconfig()?
Re: own IP address?
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).
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?
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?
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.
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?
Very elegant and concise code.
-
- Posts: 969
- Joined: Sat Feb 03, 2018 7:02 pm
Re: own IP address?
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.
So far Robert's callback driven ftp server has served me well on the esp32.
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode
Re: own IP address?
Thanks. Kevin, it's very easy to integrate any git repository into your own setup, e.g.
Perhaps not widely known due to GitHub's popularity, but git itself is a distributed version control system.
Code: Select all
git submodule add https://git.jeelabs.org/jcw/pythonx jcw-pythonx
-
- Posts: 969
- Joined: Sat Feb 03, 2018 7:02 pm
Re: own IP address?
oh, thanks. I might try that when I continue programming.
Never tried integrating a git repository that wasn't hosted on github itself.
Never tried integrating a git repository that wasn't hosted on github itself.
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode