How to find an android phone ip via using python 3 on Raspberry Pi 3 B

Viewed 638

I have a project which I need to do data communication with my android phone and Raspberry Pi 3.

Firstly, I connected raspberry pi 3 to my phone's wifi hotspot. Then with using very same code like

Sender

   1 import socket #sender
   2 
   3 UDP_IP = "127.0.0.1"
   4 UDP_PORT = 5005
   5 MESSAGE = "Hello, World!"
   6 
   7 print "UDP target IP:", UDP_IP # My phone IP
   8 print "UDP target port:", UDP_PORT
   9 print "message:", MESSAGE
  10 
  11 sock = socket.socket(socket.AF_INET, # Internet
  12                      socket.SOCK_DGRAM) # UDP
  13 sock.sendto(MESSAGE, (UDP_IP, UDP_PORT))    

which I obtained from https://wiki.python.org/moin/UdpCommunication;

I can manage the communication. However, I need to manually write UDP_IP which corresponds to my phone's IP. Problem is that sometimes the IP changes. Therefore, I need to find the phone's IP automatically so that i won't need to change.

I did the research but couldn't find it. So I need a code which finds android phone IP(not the Raspberry Pi host IP).

1 Answers
Related