diff --git a/src/ipapi.py b/src/ipapi.py index 8632038..9999fc7 100644 --- a/src/ipapi.py +++ b/src/ipapi.py @@ -19,7 +19,7 @@ import json import sys -from urllib.request import urlopen +from urllib.request import urlopen, Request import socket def internet_available(): @@ -41,3 +41,6 @@ def get_ip_info(ip): result = json.loads(urlopen("http://ip-api.com/json/{}".format(ip)).read()) return result + +def get_your_ip(): + return urlopen(Request("https://ifconfig.io", headers={"User-Agent":"curl"})).read().decode("utf-8").strip() diff --git a/src/main.py b/src/main.py index 1cfe7ca..03437c4 100644 --- a/src/main.py +++ b/src/main.py @@ -36,6 +36,7 @@ def __init__(self): flags=Gio.ApplicationFlags.FLAGS_NONE) self.create_action('quit', self.on_quit_action, ['q']) self.create_action('about', self.on_about_action) + self.create_action('get-your-ip', self.on_get_your_ip_action) def do_activate(self): """Called when the application is activated. @@ -68,6 +69,12 @@ def on_about_action(self, widget, _): copyright='Copyright© 2023 Bytez') about.present() + def on_get_your_ip_action(self, widget, _): + self.win.ip_entry.set_text(ipapi.get_your_ip()) + self.win.ip_entry.grab_focus() + self.win.ip_entry.set_position(-1) + self.on_search(self) + def on_search(self, widget): # TODO: Call deferred # TODO: Show an osd GtkProgressBar diff --git a/src/window.ui b/src/window.ui index 15c5461..0145957 100644 --- a/src/window.ui +++ b/src/window.ui @@ -205,6 +205,12 @@ +
+ + _Get Your IP + app.get-your-ip + +
_Keyboard Shortcuts