IPAddress.Address is obsolete

  • Thread starter Thread starter Michael Riggio
  • Start date Start date
M

Michael Riggio

Does anyone know why this property is obsolete? Also, is there an
alternative available?
 
Michael Riggio said:
Does anyone know why this property is obsolete?
Not specifically, but usually it's b/c they build in new funcionality and
the obsolete stuff no longer works due to a change in a dependency or
doesn't fit in the model. I'll see if I can get you a real answer to this
one b/c this is just a guess on my part
Also, is there an
alternative available?
Something like this:

Dim Ip_Address As IPHostEntry = Dns.Resolve("205.128.215.120")

MessageBox.Show(Ip_Address.HostName)
 
Thanks for taking the time to perform a test or two for me. Also,
concerning your alternative:
IPHostEntry contains a collection of IPAddress objects, so I think I'm soft
of in the same situation. The application I'm working on needs to display
the list of ipaddresses for each hostname, so I would definitely need to
iterate through that collection..
 
Michael:

I wish I knew a better answer but I'm a relative newbie to network
programming.

This will walk you through it though:
 
Michael Riggio said:
Does anyone know why this property is obsolete? Also, is there an
alternative available?

Docs say to use the GetAddressBytes method to get the address as binary
data. You should also be able to use IPAddress.ToString to get the address
in a textual notation.
 
Michael,
In addition to the other's comments:

My understanding is IPAddress.Address is obsolete as it does not support
IPv6. (internet addresses longer then 32bits).

As Daniel suggested, the GetAddressBytes call supports addresses longer then
32bits!

Hope this helps
Jay
 
Here is a tool I call IPLookup I wrote in .NET (console app) that should
show you how to use the IP lookup stuff...

Imports System.Net
Imports System.Net.Sockets
Imports System.Reflection.Assembly

Module modCore
Sub Main(ByVal cmdArgs() As String)

Dim iTotalParms As Integer = 0
iTotalParms = (UBound(cmdArgs) + 1)

Console.WriteLine("{0} {1}.{2}.{3} Copyright (C) 2004 Joseph N.
Stackhouse", _
GetExecutingAssembly.GetName.Name, _
GetExecutingAssembly.GetName().Version.Major.ToString(), _
GetExecutingAssembly.GetName().Version.Minor.ToString(), _
GetExecutingAssembly.GetName().Version.Build.ToString())

Console.WriteLine()

If (iTotalParms) <> 1 Then
Console.WriteLine("Usage: {0} <hostname>",
GetExecutingAssembly.GetName.Name)
End
End If

Dim iTotalResults As Integer = 0
Dim sIPs() As String
Dim sNames() As String

Dim DNSLookup As Dns
Dim HostLookup As Dns

Dim IPResult As New IPHostEntry

Try
IPResult = DNSLookup.GetHostByName(cmdArgs(0))
Catch ex As SocketException
Console.WriteLine("Could not resolve [{0}]:", cmdArgs(0))
Console.WriteLine()
Console.WriteLine(ex.Message)
End
Catch ex As System.ArgumentOutOfRangeException
Console.WriteLine("Cannot process your request as one or more
segments of the address you specified exceed the maximum length allowed")
End
End Try

iTotalResults = UBound(IPResult.AddressList)

Console.WriteLine("Found a total of {0} addresses for [{1}]:",
(iTotalResults + 1).ToString, cmdArgs(0))
Console.WriteLine()

ReDim sIPs(iTotalResults)
ReDim sNames(iTotalResults)

Dim i As Integer = 0

Do While i <= UBound(IPResult.AddressList)
sIPs(i) = (IPResult.AddressList(i).ToString())

Try
sNames(i) =
HostLookup.GetHostByAddress(sIPs(i)).HostName.ToString
Catch ex As Sockets.SocketException
If sNames(i) = vbNullString Then sNames(i) = "none"
End Try

Console.WriteLine("{0}.{1}{2}{3}({4})", (i + 1).ToString, vbTab,
sIPs(i), vbTab, sNames(i))
i += 1
Loop

End Sub
End Module

Alternatively you can download it from Planet Source Code at:

http://www.pscode.com/vb/scripts/ShowCode.asp?txtCodeId=1287

-L
 
Hi Jay,
So, the IPAddress type will support IPv6, but the Address property
doesn't. To get around that you're suggesting using the
IPAddress.GetAddressBytes method? So, in theory, I could derive from
IPAddress and include my own Address property that supports IPv6, and
everyone would be happy?

Thanks!
-Michael
 
Michael Riggio said:
Hi Jay,
So, the IPAddress type will support IPv6, but the Address property
doesn't. To get around that you're suggesting using the
IPAddress.GetAddressBytes method? So, in theory, I could derive from
IPAddress and include my own Address property that supports IPv6, and
everyone would be happy?

Only until a new address format comes around or you have someone who needs
to deal with both without knowing which he's handling.

Keeping everyone happy is about as easy as counting the sand in the sahara
using nothing but a hippo and three bananas.
 
Michael,
What would your address property provide that is not provided by
GetAddressBytes?

The "problem" with your theory is that Address is not overridable & to
change what it returns you would need to "shadow" it anyway (new in C#),
once you "shadow" it, the property will not function polymorphically, if I
assign one of your DerivedIPAddress objects to an IPAddress variable, the
normal Address property will be exposed...

I'm happy using IPAddress.GetAddressBytes or IPAddress.ToString.

Hope this helps
Jay
 
Back
Top