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: 220.127.116.11, $serverip would return 18.104.22.168, because it wouldn't need to resolve the server hostname.
However, it does not, it returns 255.255.255.255.
I'm not convinced the issue has been properly identified.
I am still interested to know exactly where $serverip pulls the ip address from.