Skip to content

Commit 92df91c

Browse files
committed
Added IPv6 to QR code connection
On devices with support for IPv4 (example: 192.168.1.10) and IPv6 (example: 2a02::1), the code will look like this: warpinator://192.168.1.10:42001/ipv6=2a02%3A%3A1 (%3A is ':') On devices that only do IPv6 but not IPv4, the IPv6 address will be used for the host part in the QR code url: warpinator://[2a02::1]:42001 (brackets indicate IPv6)
1 parent e89fc57 commit 92df91c

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/warpinator.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,7 +1213,14 @@ def __init__(self, parent:WarpWindow):
12131213
border=2
12141214
)
12151215

1216-
qr.add_data("warpinator://%s:%d" % (parent.current_ip, parent.current_auth_port))
1216+
ip_info = networkmonitor.get_network_monitor().current_ip_info
1217+
host_ip = ip_info.ip4_address if ip_info.ip4_address is not None else "[%s]" % ip_info.ip6_address
1218+
url_data = "%s:%d" % (host_ip, parent.current_auth_port)
1219+
if ip_info.ip4_address is not None and ip_info.ip6_address is not None:
1220+
url_data = "%s?%s" %(url_data, urllib.parse.urlencode({"ipv6": ip_info.ip6_address}))
1221+
url = "warpinator://" + url_data
1222+
logging.debug("QR code data: %s" % url)
1223+
qr.add_data(url)
12171224
img = qr.make_image()
12181225
img.save(qrbytes, "BMP")
12191226

@@ -1223,7 +1230,7 @@ def __init__(self, parent:WarpWindow):
12231230
qr_image = Gtk.Image.new_from_surface(surface)
12241231
qr_holder.add(qr_image)
12251232

1226-
ip_label.set_label("%s:%d" % (parent.current_ip, parent.current_auth_port))
1233+
ip_label.set_label(url_data)
12271234

12281235
self.set_focus(qr_holder)
12291236
self.show_all()

0 commit comments

Comments
 (0)