Write a Python to find local IP addresses using Pythons stdlib


Introduction

Write a Python to find local IP addresses using Pythons stdlib. I have used python 3.7 compiler for debugging purpose.


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

  1. import socket
  2. print([l for l in ([ip for ip in socket.gethostbyname_ex(socket.gethostname())[2]
  3. if not ip.startswith("127.")][:1], [[(s.connect(('8.8.8.8', 53)),
  4. s.getsockname()[0], s.close()) for s in [socket.socket(socket.AF_INET,
  5. socket.SOCK_DGRAM)]][0][1]]) if l][0][0])
  6.  

Result

python language techstudy.org

     





Related Topics




Popular Posts