When i pass an ip to do
_ServerAddress = Nothing
Dim remoteHost As IPHostEntry = Dns.GetHostEntry(ServerTextBox.Text)
If remoteHost IsNot Nothing AndAlso remoteHost.AddressList.Length > 0 Then
For Each deltaAddress As IPAddress In remoteHost.AddressList
If deltaAddress.AddressFamily = AddressFamily.InterNetwork Then
_ServerAddress = deltaAddress
'hard coded ip
_ServerAddress = System.Net.IPAddress.Parse("###.###.##.119")
_Connection = New ConnectionInfo(_ServerAddress, CInt(PortTextBox.Text), AddressOf InvokeAppendOutput)
There is no such thing as a wrong IP address. One DNS entry can have many IP addresses that point to the same host, on the same or on different interfaces.
Then a socket can be listening on the "any address" (0.0.0.0), or on specific addresses. If it's listening on a specific IP address and you try to connect to another one, even if it points to the same host, it'll refuse the connection.
There could also be a firewall that blocks request from a certain subnet to a certain address, when at the same time from another subnet you can connect just fine.
There's no way to know from a DNS query which address you should use. You could try to find out whether there's an address on the same subnet as the one you're connecting from. This might improve your chances of successfully connecting, but it's no guarantee.