Get IP from dynamic DSN
Get IP from dynamic DSN
Hello,
I hope I find the right word. Via dynamic DSN I can access my home network from outside without knowing the IP. Can I easily get the real IP from the address the dynamic DNS creates? Is this depending on the dynamic DNS provider or is there an universal method (if any)?
I hope I find the right word. Via dynamic DSN I can access my home network from outside without knowing the IP. Can I easily get the real IP from the address the dynamic DNS creates? Is this depending on the dynamic DNS provider or is there an universal method (if any)?
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Re: Get IP from dynamic DSN
To get the public IP adress of a machine behind a router and firewall, save the resulting html page you get from a service like www.whatsmyip.com.
I wrote a procedure years ago that parses the result and returns the numeric IP and some meta data. It's not difficult to do and my own procedure is embarrassing old, or i would paste it
I wrote a procedure years ago that parses the result and returns the numeric IP and some meta data. It's not difficult to do and my own procedure is embarrassing old, or i would paste it
Re: Get IP from dynamic DSN
You can get your PublicIP v4 or v6 address with powershell by using Invoke-RestMethod cmdlet
Or with cmd line with:
Code: Select all
IPv4: Invoke-RestMethod api.ipify.org
IPv6: Invoke-RestMethod api64.ipify.org
Code: Select all
IPv4: For /f %A in ('powershell Invoke-RestMethod api.ipify.org') do echo %A
IPv6: For /f %A in ('powershell Invoke-RestMethod api64.ipify.org') do echo %A
Re: Get IP from dynamic DSN
Gethostbyname api will resolve the ip address the dynamic dns name.
Re: Get IP from dynamic DSN
I think he want to get the internal IP of the host with the DynDNS address.Can I easily get the real IP from the address the dynamic DNS creates?
For example:
A server behind a DSL-Router.
The DynDNS is the address of the router which forwards the access to the internal server.
And he want to know the internal address of the server.
But it is not 100% clear which address he want.
So a better description is needed.
Re: Get IP from dynamic DSN
You are probably right about what jacdelad wants.
About ipify, one of the largest and most popular IP address API services on the internet, that has existed for years.
I wrote them to point out that their PureBasic code sample is outdated, InitNetwork() is deprecated since PureBasic version 6.0.
A more complete code sample to get your public IPv4 or IPv6 in plain text or in JSON format, it's so simple, easy
About ipify, one of the largest and most popular IP address API services on the internet, that has existed for years.
I wrote them to point out that their PureBasic code sample is outdated, InitNetwork() is deprecated since PureBasic version 6.0.
Code: Select all
;InitNetwork() is no more needed to use network functions (deprecated) since PureBasic 6.0
*Buffer = ReceiveHTTPMemory("https://api.ipify.org?format=json")
If *Buffer
ParseJSON(0, PeekS(*Buffer, MemorySize(*Buffer), #PB_UTF8))
FreeMemory(*Buffer)
Debug "PublicIP v4 = " + GetJSONString(GetJSONMember(JSONValue(0), "ip"))
EndIf
A more complete code sample to get your public IPv4 or IPv6 in plain text or in JSON format, it's so simple, easy
Code: Select all
;InitNetwork() is no more needed to use network functions (deprecated) since PureBasic 6.0
; Get your public IP directly (in plain text)
*Buffer = ReceiveHTTPMemory("api.ipify.org")
If *Buffer
Debug "PublicIP v4 = " + PeekS(*Buffer, MemorySize(*Buffer), #PB_UTF8|#PB_ByteLength)
FreeMemory(*Buffer)
EndIf
*Buffer = ReceiveHTTPMemory("api64.ipify.org")
If *Buffer
Debug "PublicIP v6 = " + PeekS(*Buffer, MemorySize(*Buffer), #PB_UTF8|#PB_ByteLength)
FreeMemory(*Buffer)
EndIf
; Get your public IP in JSON format
*Buffer = ReceiveHTTPMemory("https://api.ipify.org?format=json")
If *Buffer
ParseJSON(0, PeekS(*Buffer, MemorySize(*Buffer), #PB_UTF8))
FreeMemory(*Buffer)
Debug "PublicIP v4 = " + GetJSONString(GetJSONMember(JSONValue(0), "ip"))
EndIf
*Buffer = ReceiveHTTPMemory("https://api64.ipify.org?format=json")
If *Buffer
ParseJSON(0, PeekS(*Buffer, MemorySize(*Buffer), #PB_UTF8))
FreeMemory(*Buffer)
Debug "PublicIP v6 = " + GetJSONString(GetJSONMember(JSONValue(0), "ip"))
EndIf
Re: Get IP from dynamic DSN
Thanks you all. I wanted to get my public address, the internal addresses are known. I guess at least one of the methods will work.
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Re: Get IP from dynamic DSN
I don't have the code anymore, but on Windows machines I used INATExternalIPAddressCallback::NewExternalIPAddress() to get WAN IP without any service. It's part of the Firewall API. It uses UpNp IGD internally.
Just an FYI most web hosts allow you to use dynamic IP for A and even NS records. You can set short TTL to make sure it's always updated. You can even do round-robin and fast flux with entirely dynamic WAN IPs. I've setup flux and round robin on both GoDaddy and BlueHost before using only dynamic IP and polled A and NS updated with a endpoint script..
I haven't used a DDNS service since Dyn was the only provider; they actually got router integration before anyone else. Most Router manufacturers embed DDNS support in firmware. Examples: http://iplookup.asus.com/nslookup.php tplinkdns.com (Linksys and Netgear use DynDNS, TZO, and NoIP)
Just an FYI most web hosts allow you to use dynamic IP for A and even NS records. You can set short TTL to make sure it's always updated. You can even do round-robin and fast flux with entirely dynamic WAN IPs. I've setup flux and round robin on both GoDaddy and BlueHost before using only dynamic IP and polled A and NS updated with a endpoint script..
I haven't used a DDNS service since Dyn was the only provider; they actually got router integration before anyone else. Most Router manufacturers embed DDNS support in firmware. Examples: http://iplookup.asus.com/nslookup.php tplinkdns.com (Linksys and Netgear use DynDNS, TZO, and NoIP)
Last edited by tj1010 on Mon Dec 05, 2022 5:37 pm, edited 1 time in total.
The truth hurts.
Re: Get IP from dynamic DSN
Query DNS (uses nslookup)The question was: know your external IP (WAN) when you know your dynamic DNS name
(can take some secs for some IP)
Code: Select all
; Get_WAN_IP
; Query DNS without external internet service
; Windows only (easy to adapt for other os)
; Marc56 - 2022/12/05 - v1.0 - PureBasic any version
; in reply to https://www.purebasic.fr/english/viewtopic.php?t=80228
EnableExplicit
Define Compiler = RunProgram(GetEnvironmentVariable("%windir%") +
"nslookup.exe",
"list " +
InputRequester("WAN IP", "Enter Site Name", "") ,
"",
#PB_Program_Open | #PB_Program_Read)
If Compiler
While ProgramRunning(Compiler)
If AvailableProgramOutput(Compiler)
Debug ReadProgramString(Compiler)
EndIf
Wend
CloseProgram(Compiler)
EndIf
End
Code: Select all
$ sudo apt install dnsutils
Re: Get IP from dynamic DSN
On Linux you can just use tcpdump for just about everything including UpNp IGD which will get you WAN IP without a service if UpNp is enabled
Basically: No UpNp then you need a service to get NAT gateway WAN address. Windows you use tcpdump or Firewall API
Basically: No UpNp then you need a service to get NAT gateway WAN address. Windows you use tcpdump or Firewall API
The truth hurts.