forked from albertlauncher/python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ip.py
52 lines (39 loc) · 1.28 KB
/
ip.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# -*- coding: utf-8 -*-
"""Get internal and external IP address.
Synopsis: <trigger>"""
import socket
from urllib import request
from albertv0 import *
__iid__ = "PythonInterface/v0.1"
__prettyname__ = "IP Addresses"
__version__ = "1.0"
__trigger__ = "ip "
__author__ = "Manuel Schneider, Benedict Dudel"
iconPath = iconLookup("preferences-system-network")
def handleQuery(query):
if not query.isTriggered:
return None
with request.urlopen("https://ipecho.net/plain") as response:
externalIP = response.read().decode()
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("10.255.255.255", 1))
internalIP = s.getsockname()[0]
s.close()
items = []
if externalIP:
items.append(Item(
id = __prettyname__,
icon = iconPath,
text = externalIP,
subtext = "Your external ip address from ipecho.net",
actions = [ClipAction("Copy ip address to clipboard", externalIP)]
))
if internalIP:
items.append(Item(
id = __prettyname__,
icon = iconPath,
text = internalIP,
subtext = "Your internal ip address",
actions = [ClipAction("Copy ip address to clipboard", internalIP)]
))
return items