Skip to content

Commit 8627da4

Browse files
Find Zerotier Network IP
- Uses command line to find the first Zerotier Network. I'm assuming if users have more than one they'll have to adjust their IP manually
1 parent 2ce617f commit 8627da4

3 files changed

Lines changed: 27 additions & 0 deletions

File tree

src/index.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,30 @@ app.on('ready', () => {
7575
*/
7676
});
7777

78+
ipcMain.handle('get-zerotier-ip', () => {
79+
return new Promise((resolve, reject) => {
80+
exec('ipconfig', (error, stdout, stderr) => {
81+
if (error) {
82+
console.error(`Error executing ipconfig: ${error.message}`);
83+
reject(error.message);
84+
return;
85+
}
86+
const zeroTierIPRegex = /Ethernet adapter ZeroTier One[^\n]*\n(?:[^\n]*\n)*.*IPv4 Address[.\s]+: ([\d.]+)/;
87+
const match = stdout.match(zeroTierIPRegex);
88+
89+
if (match) {
90+
const zeroTierIP = match[1];
91+
// You can use the ZeroTier IP for further actions in your app.
92+
resolve(zeroTierIP);
93+
return;
94+
} else {
95+
resolve('No Zerotier Network');
96+
return;
97+
}
98+
});
99+
});
100+
});
101+
78102
autoUpdater.on('checking-for-update', () => {
79103
mainWindow.webContents.send('auto-updater-callback', 'Checking for Update');
80104
});

src/preload.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ contextBridge.exposeInMainWorld('api', {
2929
},
3030

3131
restartAndUpdate: () => ipcRenderer.invoke('restart-and-update'),
32+
getZerotierIP: () => ipcRenderer.invoke('get-zerotier-ip'),
3233
});

src/settings.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ document.addEventListener('DOMContentLoaded', async () => {
7878
settings = await api.hostSettingsHandler({request: 'Get'});
7979
if (settings === null){
8080
selectUserTypeOverlay_el.style.display = 'flex';
81+
const ztIP = await api.getZerotierIP();
82+
ipInput_el.value = ztIP;
8183
//settingsOverlay_el.style.display = 'flex';
8284
} else {
8385
await getGist();

0 commit comments

Comments
 (0)