fix ipinfo.io not returning ipv6 location info

Signed-off-by: si458 <simonsmith5521@gmail.com>

si458 committed Feb 21, 2026 at 22:09 UTC 1bc5261861c0cf21b78f4df51a51751a2e35024f
1 file changed +25 -14
agents/meshcore.js
+25 -14
@@ -960,32 +960,43 @@ var getIpLocationDataExInProgress = false;
960 var getIpLocationDataExCounts = [0, 0];
961 function getIpLocationDataEx(func) {
962 if (getIpLocationDataExInProgress == true) { return false; }
963 - try {
963 getIpLocationDataExInProgress = true;
964 getIpLocationDataExCounts[0]++;
966 - var options = http.parseUri("http://ipinfo.io/json");
965 +
966 + function tryEndpoint(url, fallback) {
967 + var options = http.parseUri(url);
968 options.method = 'GET';
969 http.request(options, function (resp) {
969 - if (resp.statusCode == 200) {
970 var geoData = '';
971 - resp.data = function (geoipdata) { geoData += geoipdata; };
971 + resp.data = function (chunk) { geoData += chunk; };
972 resp.end = function () {
973 - var location = null;
973 try {
975 - if (typeof geoData == 'string') {
974 var result = JSON.parse(geoData);
977 - if (result.ip && result.loc) { location = result; }
975 + if (result.ip && result.loc) {
976 + getIpLocationDataExInProgress = false;
977 + getIpLocationDataExCounts[1]++;
978 + func(result);
979 + return;
980 }
981 } catch (ex) { }
980 - if (func) { getIpLocationDataExCounts[1]++; func(location); }
981 - }
982 - } else
983 - { func(null); }
984 - getIpLocationDataExInProgress = false;
982 + if (fallback) { fallback(); } else { done(null); }
983 + };
984 + if (resp.statusCode != 200) { if (fallback) { fallback(); } else { done(null); } }
985 + }).on('error', function () {
986 + if (fallback) { fallback(); } else { done(null); }
987 }).end();
986 - return true;
988 }
988 - catch (ex) { return false; }
989 +
990 + function done(result) {
991 + getIpLocationDataExInProgress = false;
992 + if (func) { func(result); }
993 + }
994 +
995 + tryEndpoint('https://v6.ipinfo.io/json', function () {
996 + tryEndpoint('https://ipinfo.io/json', null);
997 + });
998 +
999 + return true;
1000 }
1001
1002 // Remove all Gateway MAC addresses for interface list. This is useful because the gateway MAC is not always populated reliably.