-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moving in robust ipv4 & ipv6 support
Certs have DIS/DNS record examples
- Loading branch information
Universal Web
committed
Oct 2, 2023
1 parent
9b18e2a
commit e350e6d
Showing
14 changed files
with
155 additions
and
4 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { forEachAsync } from '@universalweb/acid'; | ||
import axios from 'axios'; | ||
const ipv6Servers = ['https://api64.ipify.org?format=json']; | ||
const ipv4Servers = ['https://api.ipify.org?format=json']; | ||
async function fetchFromAPI(url) { | ||
try { | ||
const response = await axios.get(url); | ||
if (response.data && response.data.ip) { | ||
return response.data.ip; | ||
} else { | ||
// console.error('Failed to retrieve WAN IP address.'); | ||
} | ||
} catch (error) { | ||
// console.error('Error fetching WAN IP address:', error.message); | ||
} | ||
} | ||
async function getWANIPAddress(getBoth) { | ||
const ip6length = ipv6Servers.length; | ||
const ip4length = ipv4Servers.length; | ||
let globalIP; | ||
const results = {}; | ||
for (let i = 0; i < ip6length; i++) { | ||
const result = await fetchFromAPI(ipv6Servers[i]); | ||
if (result) { | ||
results.ip = result; | ||
if (result.includes(':')) { | ||
results.ipv6 = result; | ||
} else { | ||
results.ipv4 = result; | ||
} | ||
break; | ||
} | ||
} | ||
if (getBoth && results.ipv6) { | ||
for (let i = 0; i < ip4length; i++) { | ||
const result = await fetchFromAPI(ipv4Servers[i]); | ||
if (result) { | ||
results.ipv4 = result; | ||
break; | ||
} | ||
} | ||
} | ||
return results; | ||
} | ||
console.log(await getWANIPAddress()); |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.