Skip to content

Commit 7eafe68

Browse files
Merge pull request geekcomputers#129 from nix-py/add-pr
Script to check local and public IP address
2 parents 1fda62d + 721bc9c commit 7eafe68

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

myip.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
4+
import socket
5+
from urllib.request import urlopen
6+
7+
8+
def public_ip():
9+
read_res = urlopen('http://ipecho.net/plain').read()
10+
return read_res.decode('utf-8')
11+
12+
13+
def local_ip():
14+
return socket.gethostbyname(socket.gethostname())
15+
16+
17+
if __name__ == "__main__":
18+
print("Getting public and local IP...")
19+
print("Public IP: {}\nLocal IP: {}".format(public_ip(), local_ip()))

0 commit comments

Comments
 (0)