Page 1 sur 1

Adresse MAC

Publié : jeu. 26/oct./2006 11:22
par brossden
Bonjour à tous

Est il possible de connaitre l'adresse Mac d'une machine dont on connait l'adresse IP sur un réseau où l'on est soit même connecté ?

Pas évident je pense !! :roll:

Publié : jeu. 26/oct./2006 11:26
par Droopy
ARP permet de lister les adresses Mac avec le quel tu as communiqué récemment

Publié : jeu. 26/oct./2006 11:41
par brossden
merci droopy

Publié : jeu. 26/oct./2006 20:21
par Droopy
Tu peux pinger et ensuite matter le cache ARP.
Le seul soucis c'est que si tu ping une uc qui est sur un autre sous réseau, tu ne peux avoir son adresse Mac, car tu communique via la passerelle :wink:

Publié : ven. 27/oct./2006 7:55
par brossden
C'est ce que j'ai fait
un petit code rapide pour ceux qui seraient interessés :
C'est un regroupement rapide de choses prises ça et là qui ne demandent quà être amélioré !

Code : Tout sélectionner

Global hwnd_gadget
InitNetwork()
Enumeration 1
  #Window_Form
EndEnumeration
#WindowIndex=#PB_Compiler_EnumerationValue
Enumeration 1
 #status
  #Gadget_Form_Panel
  #Gadget_Form_Tab_1
  #Gadget_Form_Tab_2
  #Gadget_Form_String
  #Gadget_Form_Text
  #Gadget_Form_Button_compile
  #Gadget_Form_Button_Link
  #Gadget_Form_Button_Run
  #Gadget_Form_Editor_Output
  #Gadget_Form_Button_Quit
  #Gadget_Form_Editor_File
  #Gadget_Form_Button_OK
  
  
EndEnumeration
#GadgetIndex=#PB_Compiler_EnumerationValue
Structure MySTARTUPINFO
  cb.l
  lpReserved.l
  lpDesktop.l
  lpTitle.l
  dwX.l
  dwY.l
  dwXSize.l
  dwYSize.l
  dwXCountChars.l
  dwYCountChars.l
  dwFillAttribute.l
  dwFlags.l
  wShowWindow.w
  cbReserved2.w
  lpReserved2.l
  hStdInput.l
  hStdOutput.l
  hStdError.l
EndStructure

Procedure.s GetProgramResult(Command.s)
  
  proc.PROCESS_INFORMATION ;Process info filled by CreateProcessA
  ret.l ;long variable For get the Return value of the
  start.MySTARTUPINFO ;StartUp Info passed To the CreateProceeeA
  sa.SECURITY_ATTRIBUTES ;Security Attributes passeed To the
  hReadPipe.l ;Read Pipe handle created by CreatePipe
  hWritePipe.l ;Write Pite handle created by CreatePipe
  lngBytesread.l ;Amount of byte Read from the Read Pipe handle
  strBuff.s=Space(256) ;String buffer reading the Pipe
  
  ;Consts For functions
  #NORMAL_PRIORITY_CLASS = $20
  #STARTF_USESTDHANDLES = $100
  #STARTF_USESHOWWINDOW = $1
  
  ;Create the Pipe
  sa\nLength =SizeOf(SECURITY_ATTRIBUTES) ;Len(sa)
  sa\bInheritHandle = 1
  sa\lpSecurityDescriptor = 0
  ret = CreatePipe_(@hReadPipe, @hWritePipe, @sa, 0)
  If ret = 0
    ;If an error occur during the Pipe creation exit
    MessageRequester("info", "CreatePipe failed. Error: ",0)
    End
  EndIf
  
  
  start\cb = SizeOf(MySTARTUPINFO)
  start\dwFlags = #STARTF_USESHOWWINDOW | #STARTF_USESTDHANDLES
  
  ;set the StdOutput And the StdError output To the same Write Pipe handle
  start\hStdOutput = hWritePipe
  start\hStdError = hWritePipe
  
  ;Execute the command
  ret = CreateProcess_(0, Command, sa, sa, 1, #NORMAL_PRIORITY_CLASS, 0, 0, @start, @proc)
  
  If ret <> 1
    retour.s=""
  Else
    
    ;Now We can ... must close the hWritePipe
    ret = CloseHandle_(hWritePipe)
    
    mOutputs.s = ""
    
    ;Read the ReadPipe handle
    While ret<>0
      ret = ReadFile_(hReadPipe, strBuff, 255, @lngBytesread, 0)
      If lngBytesread>0
        mOutputs = mOutputs + Left(strBuff, lngBytesread)
      EndIf
    Wend
    
    ;Close the opened handles
    ret = CloseHandle_(proc\hProcess)
    ret = CloseHandle_(proc\hThread)
    ret = CloseHandle_(hReadPipe)
    ;ret=CloseHandle_(hWritePipe)
    
    retour.s=mOutputs
    
  EndIf
  
  ProcedureReturn mOutputs
EndProcedure





Procedure.l Window_Form()
  If OpenWindow(#Window_Form,80,80,740,625,"Liste des Clients du réseau",#PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_Invisible)
    If CreateGadgetList(WindowID(#Window_Form))
      hwnd_gadget=EditorGadget(#Gadget_Form_String,5,160,710,420)
      ButtonGadget(#Gadget_Form_Button_Run,655,95,60,40,"Run")
      SetGadgetFont(#Gadget_Form_String,LoadFont(#Gadget_Form_String,"Courier New",8,0)) 
      CreateStatusBar(#status, WindowID(#Window_Form))
       AddStatusBarField(190)
      HideWindow(#Window_Form,0)
      ProcedureReturn WindowID(#Window_Form)
    EndIf
  EndIf
EndProcedure

If Window_Form()
  SendMessage_(hwnd_gadget, #EM_SETBKGNDCOLOR, 0, RGB(160,160,160)) 
  quitForm=0
  ExamineIPAddresses()
  Adresse.s =IPString(NextIPAddress())
  For n=Len(Adresse) To 1 Step -1
    If Mid(Adresse,n,1)="."
      Point=n
      n=0
      EndIf
    Next  
    AdressIP.s=Left(Adresse,Point)
  AddGadgetItem(#Gadget_Form_String,-1,AdressIP+"xxx")
  Repeat
    EventID  =WaitWindowEvent()
    MenuID   =EventMenu()
    GadgetID =EventGadget()
    WindowID =EventWindow()
    
    Select EventID
      Case #PB_Event_CloseWindow
        If WindowID=#Window_Form
          quitForm=1
        EndIf
        
      Case #PB_Event_Gadget
        Select GadgetID
          Case #Gadget_Form_Button_Run

            
            AddGadgetItem(#Gadget_Form_String,-1, "Traitement en cours...")
            Commande.s="cmd /c arp -d *" ; 
            Text.s = GetProgramResult(Commande)
            For n=1 To 255
                StatusBarText(#status, 0, AdressIP+Str(n)) 
              Commande.s="cmd /c ping -n 1 "+AdressIP+Str(n) +" -w 500"
              Text.s = GetProgramResult(Commande)
              Delay(100)
            Next
            Delay(500)
            Commande.s="cmd /c arp -a" ; 
            Text.s = GetProgramResult(Commande)
            pos = FindString(Text,"Type",1)+ 6
            AddGadgetItem(#Gadget_Form_String,-1,"  Adresse IP            Adresse Mac           Type" )
            AddGadgetItem(#Gadget_Form_String,-1,  Mid(Text,pos,100000))
            
        EndSelect
        
    EndSelect
  Until quitForm
  CloseWindow(#Window_Form)
EndIf
End