How do I get MAC and IP addresses associated with a client socket returned from socket.accept()? #13353
Unanswered
jimkoke
asked this question in
Libraries & Drivers
Replies: 2 comments 2 replies
-
Hi |
Beta Was this translation helpful? Give feedback.
1 reply
-
Are you assuming that the client is on the same physical network? In these cases the most revenant MAC address is that of the routers interface that you are sending your reply to. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I've got an application running on Pi-Pico that listens for client connections and performs various tasks. In order to perform some of these, I need the client host's MAC and IP addresses. I know I can ask the the client to provide these as part of the request, however, I believe I should be able to extract these from the client socket provided by the accept() function, which simplifies the API and streamlines the requests.
I have searched extensively (but apparently not enough) and found several solutions, however, those work for "Python" but do not work for micropython.
The code uses "socket.socket()" to get the service's socket, the listens on that socket, finally, accept() to get the client socket. The code is not so concise, I would have to cobble it together if need by, but it seems fairly standard, taking the code from Internet examples.
[UPDATE}
After reading sophiedegran's question, and smacking myself on the forehead, I realized that I have the requestor's IP address already. I did not realize it because I blindly copy-n-pasted code without reading it thoroughly:
I'm adding this line to get the requestor's IP and port
I am now left with finding the requestor's MAC address. All of the answers I have found use ARP, which might work, if these IOT processors would respond. It just seems there would be some access to the MAC layer of the incoming packet.
Beta Was this translation helpful? Give feedback.
All reactions