Skip to content

Commit 89427c1

Browse files
committed
Get your IP from menu
1 parent 3660089 commit 89427c1

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

src/ipapi.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
import json
2121
import sys
22-
from urllib.request import urlopen
22+
from urllib.request import urlopen, Request
2323
import socket
2424

2525
def internet_available():
@@ -41,3 +41,6 @@ def get_ip_info(ip):
4141
result = json.loads(urlopen("http://ip-api.com/json/{}".format(ip)).read())
4242

4343
return result
44+
45+
def get_your_ip():
46+
return urlopen(Request("https://ifconfig.io", headers={"User-Agent":"curl"})).read().decode("utf-8").strip()

src/main.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def __init__(self):
3636
flags=Gio.ApplicationFlags.FLAGS_NONE)
3737
self.create_action('quit', self.on_quit_action, ['<primary>q'])
3838
self.create_action('about', self.on_about_action)
39+
self.create_action('get-your-ip', self.on_get_your_ip_action)
3940

4041
def do_activate(self):
4142
"""Called when the application is activated.
@@ -68,6 +69,12 @@ def on_about_action(self, widget, _):
6869
copyright='Copyright© 2023 Bytez')
6970
about.present()
7071

72+
def on_get_your_ip_action(self, widget, _):
73+
self.win.ip_entry.set_text(ipapi.get_your_ip())
74+
self.win.ip_entry.grab_focus()
75+
self.win.ip_entry.set_position(-1)
76+
self.on_search(self)
77+
7178
def on_search(self, widget):
7279
# TODO: Call deferred
7380
# TODO: Show an osd GtkProgressBar

src/window.ui

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,12 @@
205205
</child>
206206
</template>
207207
<menu id="primary_menu">
208+
<section>
209+
<item>
210+
<attribute name="label" translatable="yes">_Get Your IP</attribute>
211+
<attribute name="action">app.get-your-ip</attribute>
212+
</item>
213+
</section>
208214
<section>
209215
<item>
210216
<attribute name="label" translatable="yes">_Keyboard Shortcuts</attribute>

0 commit comments

Comments
 (0)