Finding local IP addresses using Python's stdlib

后端 未结 30 3066
北恋
北恋 2020-11-21 23:54

How can I find local IP addresses (i.e. 192.168.x.x or 10.0.x.x) in Python platform independently and using only the standard library?

30条回答
  •  耶瑟儿~
    2020-11-22 00:23

    I'm afraid there aren't any good platform independent ways to do this other than connecting to another computer and having it send you your IP address. For example: findmyipaddress. Note that this won't work if you need an IP address that's behind NAT unless the computer you're connecting to is behind NAT as well.

    Here's one solution that works in Linux: get the IP address associated with a network interface.

提交回复
热议问题