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
> Michael,
> In addition to the other's comments:
[quoted text clipped - 10 lines]
> > Does anyone know why this property is obsolete? Also, is there an
> > alternative available?
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,
> In addition to the other's comments:
[quoted text clipped - 10 lines]
> > Does anyone know why this property is obsolete? Also, is there an
> > alternative available?
Daniel O'Connell [C# MVP] - 17 May 2004 22:51 GMT
> 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.
> Thanks!
> -Michael
[quoted text clipped - 14 lines]
>> > Does anyone know why this property is obsolete? Also, is there an
>> > alternative available?
Jay B. Harlow [MVP - Outlook] - 18 May 2004 01:48 GMT
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
> Hi Jay,
> So, the IPAddress type will support IPv6, but the Address property
[quoted text clipped - 21 lines]
> > > Does anyone know why this property is obsolete? Also, is there an
> > > alternative available?