Skip to content

Commit

Permalink
List IPs of domain names
Browse files Browse the repository at this point in the history
  • Loading branch information
Bytezz committed Nov 12, 2024
1 parent 0a8f1d3 commit c538af9
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 11 deletions.
26 changes: 26 additions & 0 deletions src/ipapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 11 additions & 3 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -131,3 +138,4 @@ def main(version):
app = IplookupApplication()
return app.run(sys.argv)


1 change: 0 additions & 1 deletion src/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
8 changes: 1 addition & 7 deletions src/window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,10 @@
<object class="AdwPreferencesGroup">
<property name="title" translatable="yes">Network</property>
<child>
<object class="AdwActionRow" id="ip_row">
<object class="AdwExpanderRow" id="ip_row">
<property name="title" translatable="yes">IP</property>
<property name="icon-name">globe-symbolic</property>
<property name="visible">False</property>
<child>
<object class="GtkLabel" id="ip_label">
<property name="label"></property>
<property name="selectable">True</property>
</object>
</child>
</object>
</child>
<child>
Expand Down

0 comments on commit c538af9

Please sign in to comment.