-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
44 lines (29 loc) · 1.49 KB
/
main.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
import logging
from ulauncher.api.client.EventListener import EventListener
from ulauncher.api.client.Extension import Extension
from ulauncher.api.shared.action.CopyToClipboardAction import CopyToClipboardAction
from ulauncher.api.shared.action.RenderResultListAction import RenderResultListAction
from ulauncher.api.shared.event import KeywordQueryEvent
from ulauncher.api.shared.item.ExtensionResultItem import ExtensionResultItem
import findip
logger = logging.getLogger(__name__)
class IpCopyExtension(Extension):
def __init__(self):
super(IpCopyExtension, self).__init__()
self.subscribe(KeywordQueryEvent, KeywordQueryEventListener())
class KeywordQueryEventListener(EventListener):
def on_event(self, event, extension):
items = []
ext_ip = findip.get_external_ip()
int_ip = findip.get_local_ip()
items.append(ExtensionResultItem(icon='images/icon.png',
name='Local IP',
description='IP: %s' % int_ip,
on_enter=CopyToClipboardAction(int_ip)))
items.append(ExtensionResultItem(icon='images/icon.png',
name='External IP',
description='IP: %s' % ext_ip,
on_enter=CopyToClipboardAction(ext_ip)))
return RenderResultListAction(items)
if __name__ == '__main__':
IpCopyExtension().run()