It seems that you are saying that using SOCKS by nature means DNS won't work.

If this was the case, when connecting directly to the server ip, eg:, $serverip would return, because it wouldn't need to resolve the server hostname.

However, it does not, it returns

I'm not convinced the issue has been properly identified.

I am still interested to know exactly where $serverip pulls the ip address from.