cs_olfafoufa
Messages postés16Date d'inscriptiondimanche 2 mai 2010StatutMembreDernière intervention11 mai 2012
-
27 avril 2012 à 14:39
NHenry
Messages postés15113Date d'inscriptionvendredi 14 mars 2003StatutModérateurDernière intervention22 avril 2024
-
27 avril 2012 à 21:11
bonjour
je développe ce code mais il y a des erreurs qui sont incompréhensibles
est ce qu'il y a quelqu'un qui peut m'aider svp j'ai besoin de ce code
Private Declare Function inet_addr Lib "wsock32.dll" _
(ByVal s As String) As Long
Private Declare Function SendARP Lib "iphlpapi.dll" _
(ByVal DestIP As Long, _
ByVal SrcIP As Long, _
pMacAddr As Long, _
PhyAddrLen As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" _
Alias "RtlMoveMemory" _
(dst As Any, _
src As Any, _
ByVal bcount As Long)
Private Sub Form_Load()
Text1.Text = "192.168.1.101" 'or address of interest
Text2.Text = ""
Command1.Caption = "Get Remote Mac Address"
End Sub
Private Sub Command1_Click()
Dim sRemoteMacAddress As String
If Len(Text1.Text) > 0 Then
If GetRemoteMACAddress(Text1.Text, sRemoteMacAddress, "-") Then
Text2.Text = sRemoteMacAddress
Else
Text2.Text = "(SendARP call failed)"
End If
End If
End Sub
Private Function GetRemoteMACAddress(ByVal sRemoteIP As String, _
sRemoteMacAddress As String, _
sDelimiter As String) As Boolean
Dim dwRemoteIP As Long
Dim pMacAddr As Long
Dim bpMacAddr() As Byte
Dim PhyAddrLen As Long
'convert the string IP into
'an unsigned long value containing
'a suitable binary representation
'of the Internet address given
dwRemoteIP = ConvertIPtoLong(sRemoteIP)
If dwRemoteIP <> 0 Then
'must set this up first!
PhyAddrLen = 6
'assume failure
GetRemoteMACAddress = False
'retrieve the remote MAC address
If SendARP(dwRemoteIP, 0&, pMacAddr, PhyAddrLen) = NO_ERROR Then
If (pMacAddr <> 0) And (PhyAddrLen <> 0) Then
'returned value is a long pointer
'to the MAC address, so copy data
'to a byte array
ReDim bpMacAddr(0 To PhyAddrLen - 1)
CopyMemory bpMacAddr(0), pMacAddr, ByVal PhyAddrLen
'convert the byte array to a string
'and return success
sRemoteMacAddress = MakeMacAddress(bpMacAddr(), sDelimiter)
GetRemoteMACAddress = True
End If 'pMacAddr
End If 'SendARP
End If 'dwRemoteIP
End Function
Private Function ConvertIPtoLong(sIpAddress) As Long
ConvertIPtoLong = inet_addr(sIpAddress)
End Function
Private Function MakeMacAddress(b() As Byte, sDelim As String) As String
Dim cnt As Long
Dim buff As String
On Local Error GoTo MakeMac_error
'so far, MAC addresses are
'exactly 6 segments in size (0-5)
If UBound(b) = 5 Then
'concatenate the first five values
'together and separate with the
'delimiter char
For cnt = 0 To 4
buff = buff & Right$("00" & Hex(b(cnt)), 2) & sDelim
Next
'and append the last value
buff = buff & Right$("00" & Hex(b(5)), 2)
End If 'UBound(b)
MakeMacAddress = buff
MakeMac_exit:
Exit Function
MakeMac_error:
MakeMacAddress = "(error building MAC address)"
Resume MakeMac_exit
NHenry
Messages postés15113Date d'inscriptionvendredi 14 mars 2003StatutModérateurDernière intervention22 avril 2024159 27 avril 2012 à 19:38
Bonjour,
"il y a des erreurs qui sont incompréhensibles "
Quelles erreurs ?
Pour le code, lire le point 2 de ma signature.
Tu es en VB6 ou VBA, pas .NET :
VB.NET et VB 2005 > Réseaux & Internet > Internet
Je déplace, prends en note la catégorie.
---------------------------------------------------------------------
[list=ordered][*]Pour poser correctement une question et optimiser vos chances d'obtenir des réponses, pensez à lire le règlement CS, celui-ci pour bien poser votre question ou encore celui-ci pour les PFE et autres exercices[*]Quand vous postez un code, merci d'utiliser la coloration syntaxique (3ième icône en partant de la droite : )
[*]En VB.NET pensez à activer Option Explicit et Option Strict (propriété du projet) et à retirer l'import automatique de l'espace de nom Microsoft.VisualVasic (onglet Références dans les propriétés du projet).
[*]Si votre problème est résolu (et uniquement si c'est le cas), pensez à mettre "Réponse acceptée" sur le ou les messages qui vous ont aidés./list ---
---------------------------------------------------------------------
[list=ordered][*]Pour poser correctement une question et optimiser vos chances d'obtenir des réponses, pensez à lire le règlement CS, celui-ci pour bien poser votre question ou encore celui-ci pour les PFE et autres exercices[*]Quand vous postez un code, merci d'utiliser la coloration syntaxique (3ième icône en partant de la droite : )
[*]En VB.NET pensez à activer Option Explicit et Option Strict (propriété du projet) et à retirer l'import automatique de l'espace de nom Microsoft.VisualVasic (onglet Références dans les propriétés du projet).
[*]Si votre problème est résolu (et uniquement si c'est le cas), pensez à mettre "Réponse acceptée" sur le ou les messages qui vous ont aidés./list ---