From c538af9b1e70c26ec43daad031b7d2ccd6994a76 Mon Sep 17 00:00:00 2001 From: Bytez <25850701+Bytezz@users.noreply.github.com> Date: Tue, 12 Nov 2024 13:46:18 +0100 Subject: [PATCH] List IPs of domain names --- src/ipapi.py | 26 ++++++++++++++++++++++++++ src/main.py | 14 +++++++++++--- src/window.py | 1 - src/window.ui | 8 +------- 4 files changed, 38 insertions(+), 11 deletions(-) diff --git a/src/ipapi.py b/src/ipapi.py index 118a179..03ee3f2 100644 --- a/src/ipapi.py +++ b/src/ipapi.py @@ -30,6 +30,32 @@ def internet_available(): except: return False +def resolve_to_ipv4(hostname): + ips = [] + try: + for i in socket.getaddrinfo(hostname, None, socket.AF_INET): + ips.append(i[4][0]) + ips = list(set(ips)) + return ips + except: + return ips + +def resolve_to_ipv6(hostname): + ips = [] + try: + for i in socket.getaddrinfo(hostname, None, socket.AF_INET6): + ips.append(i[4][0]) + ips = list(set(ips)) + return ips + except: + return ips + +def resolve_ips(hostname): + ips = [] + ips += resolve_to_ipv4(hostname) + ips += resolve_to_ipv6(hostname) + return ips + def is_ip(address): if not "." in address: return False diff --git a/src/main.py b/src/main.py index 04bf752..ed980de 100644 --- a/src/main.py +++ b/src/main.py @@ -75,6 +75,9 @@ def on_get_your_ip_action(self, widget, _): self.win.ip_entry.set_position(-1) self.on_search(self) + def remove_ip_row(self, _, row): + self.win.ip_row.remove(row) + def on_search(self, widget): # TODO: Call deferred # TODO: Show an osd GtkProgressBar @@ -84,9 +87,13 @@ def on_search(self, widget): if ipinfo != {} and ipinfo["status"] == "success": if not ipapi.is_ip(self.win.ip_entry.get_text()): - #self.win.ip_entry.set_text(ipinfo["query"]) - #self.win.ip_entry.set_position(-1) - self.win.ip_label.set_label(ipinfo["query"]) + self.win.ip_row.set_subtitle(ipinfo["query"]) + + for i in ipapi.resolve_ips(self.win.ip_entry.get_text()): + row = Adw.ActionRow(title=i, title_selectable=True) + self.win.ip_entry.connect("apply", self.remove_ip_row, row) + self.win.ip_row.add_row(row) + self.win.ip_row.set_visible(True) # TODO: Animate else: self.win.ip_row.set_visible(False) @@ -131,3 +138,4 @@ def main(version): app = IplookupApplication() return app.run(sys.argv) + diff --git a/src/window.py b/src/window.py index e01e4f9..b6ef02e 100644 --- a/src/window.py +++ b/src/window.py @@ -33,7 +33,6 @@ class IplookupWindow(Adw.ApplicationWindow): ip_row = Gtk.Template.Child() toast = Gtk.Template.Child() - ip_label = Gtk.Template.Child() network_label = Gtk.Template.Child() city_label = Gtk.Template.Child() country_label = Gtk.Template.Child() diff --git a/src/window.ui b/src/window.ui index 0145957..0de5a5e 100644 --- a/src/window.ui +++ b/src/window.ui @@ -61,16 +61,10 @@ Network - + IP globe-symbolic False - - - - True - -