|
-
Sep 27th, 2009, 05:41 PM
#1
Thread Starter
Fanatic Member
Obsolete property
Hi,
I got this warning:
Warning 1 'Public Property Address() As Long' is obsolete: 'This property has been deprecated. It is address family dependent. Please use IPAddress.Equals method to perform comparisons. http://go.microsoft.com/fwlink/?linkid=14202' E:\_Visual Studio_\2008\VB\Pinger\classPinger\pingerbib.vb 167 38 pingerbib
with this code:
Code:
Dim ipaddress As IPAddress
Dim ip As Integer = CInt(Net.IPAddress.Parse(IP_adresse).Address
Anyone know what the correct code is??
Last edited by Arve K.; Sep 27th, 2009 at 06:40 PM.
-
Sep 27th, 2009, 08:09 PM
#2
Re: Obsolete property
First up, read the error message. It says that the Address property is what's obsolete, not the part that you've underlined. It also suggests what you should be doing. It even says "please", which is rather polite for an error message, don't you think?
That said, I can't tell from your code what you're actually trying to accomplish, so I can't say for sure how you should accomplish it. An explanation of what you're actually trying to do is always a good idea if you want us to tell you what code to use to accomplish it.
-
Oct 15th, 2009, 07:14 PM
#3
Thread Starter
Fanatic Member
Re: Obsolete property
Hey, I must have forgotten about this thread 
But to help you help me, here's some more of the code 
vb Code:
Private Declare Function SendARP Lib "iphlpapi.dll" (ByVal DestIP As Integer, ByVal SrcIP As Integer, ByRef pMacAddr As Long, ByRef PhyAddrLen As Integer) As Integer
Public Overrides Function Execute(ByVal ipAddress As IPAddress) As ColumnValue
Dim ResultatOUI As String = Nothing
Try
Dim ip As Integer = CInt(Net.IPAddress.Parse(ipAddress.ToString).Address)
Dim mem As Long
Dim ret As Integer = SendARP(ip, 0, mem, 6)
Dim ab() As Byte = BitConverter.GetBytes(mem)
Dim OUI As String = BitConverter.ToString(ab, 0, 3) '<-- forandre 3 til 6 for å få hele mac-adressen
'PS: OUI = mac address...
Using sr As IO.StreamReader = New IO.StreamReader(Application.StartupPath & "\ieee_oui.txt")
Dim line As String
Do
line = sr.ReadLine()
If line.Contains(OUI) Then
ResultatOUI = line.Remove(0, 18)
End If
Loop Until line Is Nothing
sr.Close()
End Using
Catch ex As Exception
'do nothing
End Try
Return New ColumnValue(ColumnIndex, ResultatOUI)
End Function
The purpose of this code is this:
Let us say I have a device on my network with ip 192.168.100.100. I then use this code to get that devices mac address. I use the mac address to get the device manufacturer.
The code works fine, it's not that, but I get this warning as mentioned earlier. When I change it to..:
vb Code:
Dim ip As Integer = CInt(Net.IPAddress.Parse(ipAddress.ToString).Equals)
...I get this error:
Overload resolution failed because no accessible 'Equals' accepts this number of arguments.
So I don't know if I should just leave it as it is, or maybe someone here might know what to do?
-
Oct 15th, 2009, 07:24 PM
#4
Re: Obsolete property
You still haven't actually explained what the line of code that is giving you the messages is trying to do. The error message says:
Please use IPAddress.Equals method to perform comparisons.
Are you performing a comparison? If not the you wouldn't use Equals. Have you read the documentation for the IPAddress.Address property? Why is that not the obvious next step? That documentation says:
This property is obsolete. Use GetAddressBytes.
and kindly provides a link to the documentation for that property. The BitConverter class, which you're already using, can convert those Bytes to an Integer.
-
Oct 15th, 2009, 07:56 PM
#5
Thread Starter
Fanatic Member
Re: Obsolete property
Sorry jmcilhinney, but I give up. I understand that you're trying to help me, but I just can't seem to find an answer. And as long as the code works, I won't give it any more thought. 
PS: The codeline changes the (example) string 192.168.1.34 to integer 570534080
-
Oct 15th, 2009, 08:15 PM
#6
Re: Obsolete property
What string? Your Execute method takes an IPAddress as an argument, not a String. You've already got an IPAddress object. Call its GetAddressBytes method to get a Byte array. Pass that array to BitConverter.ToInt32 to get an Integer.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|