How can I connect via socket using DNS name from no-ip? or Is there a way to get the IP from no-ip dns name?
working
$cnt = socket_connect($socket,"100.100.100.100",$port);
but the IP is dynamic. I need something like:
$cnt = socket_connect($socket, "blablabla.ddns.net",$port);
I´ve tried gethostbyname() but it returns the same IP for all no-ip name.
This solution would depend on your server, but you can fallback to native operating system capabilities. For example, most Linux installs have
glibc
, allowing you to run a command like:Now, PHP functions like
exec()
andsystem()
can be used to run stuff like this.For example:
Then use the IP to connect to your socket.
NOTE: Please do not pass user provided input into this unless you want to have a bad time.
REFERENCES: https://unix.stackexchange.com/questions/20784/how-can-i-resolve-a-hostname-to-an-ip-address-in-a-bash-script