Hello
Does anyone know how to do this is vb2005?
Thanks :-)
Printable View
Hello
Does anyone know how to do this is vb2005?
Thanks :-)
The IPAddress class.
Thanks
I have looked at the class in msdn but it went way over my head (newbie here)
Could you explain a little more?
I did a find for decimal on teh page also but did not find anything
Thanks
What exactly are you starting with? Number? String? What format? What exactly do you want to end up with? Example?
Hello
I start with decimal 3420263445
need to end up with 203.221.20.21
Thanks :-)
I found this..
The easiest way to do it is to depict the ip address in binary. Take 3420263445 and convert to binary using any calculator that will do decimal to binary conversion (like the one that comes with Windows/95/98/NT):
binary address: 11001011.11011101.00010100.00010101
Then convert each octet back to decimal and you get: 203.221.20.21
But I don't know how to do that either :-(
This code returns the address 21.20.221.203. You are obviously using a value that has the opposite endedness to what the IPAddress class is looking for. To fix that you can convert the original number to bytes and reverse the order:VB Code:
Dim ip As New Net.IPAddress(3420263445) Dim address As String = ip.ToString()Note the "UI" suffix on the number to force it to an unsigned integer. If you don't do that it will be interpreted as a Long and the Byte array returned by GetBytes will be 8 bytes long instead of 4.VB Code:
Dim bytes As Byte() = BitConverter.GetBytes(3420263445[U]UI[/U]) Array.Reverse(bytes) Dim ip As New Net.IPAddress(bytes) Dim address As String = ip.ToString()
That is perfect!
Thanks once again for answering my question.
Do you know how to go back again?
So if I started with 203.221.20.21
Sorry if I am pushing my luck!
Thanks
This may be a way
http://www.spiderhunter.com/IpDecimal/
Your IpAddress is 150.101.162.165:
1. 150 * 256 + 101 = 38,501
2. 38501 * 256 + 162 = 9,856,418
3. 9856418 * 256 + 165 = 2,523,243,173
Hi,
VB Code:
Dim ip As IPAddress = Dns.GetHostAddresses(Dns.GetHostName())(0) MessageBox.Show(ip.ToString)