[Résolu]API PhysicalAddress

Sujets variés concernant le développement en PureBasic
wolfjeremy
Messages : 1202
Inscription : sam. 31/déc./2005 23:52

[Résolu]API PhysicalAddress

Message par wolfjeremy »

Salut,

Je voulais savoir comment je peut avoir l'adresse physique ?

Dans la documentation de Microsoft.NET framework SDK v2.0 j'ai trouver se qu'il faut normalement (ici dans l'aide ms-help://MS.NETFramework.v20.fr/cpref10/html/T_System_Net_NetworkInformation_PhysicalAddress.htm)
Mais comme je suis nul je n'arrive pas a m'en servir :lol:

pouvez vous me faire un exemple pour recuperer une adresse physique ?

Merci d'avance pour votre aide :oops:
Dernière modification par wolfjeremy le mer. 12/avr./2006 15:50, modifié 1 fois.
wolfjeremy
Messages : 1202
Inscription : sam. 31/déc./2005 23:52

Message par wolfjeremy »

Si quelqu'un connait le VB, voici le code traduit en VB :
Public Shared Sub ShowNetworkInterfaces()
Dim computerProperties As IPGlobalProperties = IPGlobalProperties.GetIPGlobalProperties
Dim nics() As NetworkInterface = NetworkInterface.GetAllNetworkInterfaces
Console.WriteLine("Interface information for {0}.{1} ", computerProperties.HostName, computerProperties.DomainName)
If ((nics = Nothing) _
OrElse (nics.Length < 1)) Then
Console.WriteLine(" No network interfaces found.")
Return
End If
Console.WriteLine(" Number of interfaces .................... : {0}", nics.Length)
For Each adapter As NetworkInterface In nics
Dim properties As IPInterfaceProperties = adapter.GetIPProperties
' .GetIPInterfaceProperties();
Console.WriteLine
Console.WriteLine(adapter.Description)
Console.WriteLine(String.Empty.PadLeft(adapter.Description.Length, Microsoft.VisualBasic.ChrW(61)))
Console.WriteLine(" Interface type .......................... : {0}", adapter.NetworkInterfaceType)
Console.Write(" Physical address ........................ : ")
Dim address As PhysicalAddress = adapter.GetPhysicalAddress
Dim bytes() As Byte = address.GetAddressBytes
Dim i As Integer = 0
Do While (i < bytes.Length)
' Display the physical address in hexadecimal.
Console.Write("{0}", bytes(i).ToString("X2"))
' Insert a hyphen after each byte, unless we are at the end of the
' address.
If (i _
<> (bytes.Length - 1)) Then
Console.Write("-")
End If
i = (i + 1)
Loop
Console.WriteLine
Next
End Sub
VOila... j'espere que quelqu'un pourra m'aider car j'ai vraiment besoin de savoir l'adresse physique (mac) :cry:

P.S.: en delphi là : http://delphi.developpez.com/faq/?page= ... adressemac
scaraber
Messages : 362
Inscription : ven. 15/juil./2005 17:32

Message par scaraber »

Salut
je connait quelqun qui programme en delphi et je peu lui demander quil te compile le code et renvoyant dans un fichier cette adresse ou plus simplment faire une dll qui le ferais ...
je ne garenti rien il est pas mal ocuper mais bon on peu toujour sessayer qu'en dis-tu?
A+
scaraber
wolfjeremy
Messages : 1202
Inscription : sam. 31/déc./2005 23:52

Message par wolfjeremy »

Oui sa serait interessant si il pouvait faire une dll qui recup l'adresse.

Merci pour ton aide c'est sympa :)

P.S.: l'adresse physique (mac) que je veut c'est celle que l'on peut trouver dans le statut du reseau local, je suppose que c'est celle de la carte reseau integrer a la carte mere mais je ne suis pas sur.
erix14
Messages : 480
Inscription : sam. 27/mars/2004 16:44
Contact :

Message par erix14 »

Tu n'as pas cherché beaucoup, sur le forum anglais en cherchant "mac address" tu aurais trouvé ton bonheur http://www.purebasic.fr/english/viewtop ... ac+address
scaraber
Messages : 362
Inscription : ven. 15/juil./2005 17:32

Message par scaraber »

SAlut
voila jai fait un petit prog suite a la decouverte de la commande qur tu nous as signaler pour recup dans le presse papier l'adresse ip et adresse mac plus pratique que de devori lancer le cmd puis de taaper ipconfig et de recopier l'ip a la main ...

Voici le programme.

ICI>ip.exe
Image
wolfjeremy
Messages : 1202
Inscription : sam. 31/déc./2005 23:52

Message par wolfjeremy »

erix14 je suis nul en anglais :oops:
gansta93
Messages : 1448
Inscription : jeu. 26/févr./2004 11:17
Localisation : Le Village
Contact :

Message par gansta93 »

Code : Tout sélectionner

; http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iphlp/iphlp/getadaptersinfo.asp
; with the help of IPHlpAPI.inc from the Powerbasic include-file for the structures
; Microsoft isn´t quite a help here :-)

Structure IP_ADDR_STRING
  pNext.l
  IpAddress.b[16]
  IpMask.b[16]
  Context.l
EndStructure

Structure IP_ADAPTER_INFO
  Next.l
  ComboIndex.l
  AdapterName.b[260] ; MAX_ADAPTER_NAME_LENGTH + 4
  Description.b[132] ; MAX_ADAPTER_DESCRIPTION_LENGTH + 4
  AdressLength.l
  Address.b[8] ; MAX_ADAPTER_ADDRESS_LENGTH
  Index.l
  Type.l
  DhcpEnabled.l
  CurrentIpAddressPTR.l
  IpAddressList.IP_ADDR_STRING
  GatewayList.IP_ADDR_STRING
  DhcpServer.IP_ADDR_STRING
  HaveWins.l
  PrimaryWinsServer.IP_ADDR_STRING
  SecondaryWinsServer.IP_ADDR_STRING
  LeaseObtained.l
  LeaseExpires.l
EndStructure

length.l=0
result=GetAdaptersInfo_(0,@length) ; Get the length for Buffer
If result=#ERROR_BUFFER_OVERFLOW
  *Buffer=AllocateMemory(length)
  result=GetAdaptersInfo_(*Buffer,@length)
  If result=#ERROR_SUCCESS
    adapters=length/SizeOf(IP_ADAPTER_INFO)
    For x=0 To adapters-1
      Debug "AdapterNr : "+Str(x+1)
      tempipinfo.IP_ADAPTER_INFO
      For i=0 To SizeOf(IP_ADAPTER_INFO)-1
        byte.b=PeekB(*Buffer+(x*640)+i)
        PokeB(tempipinfo+i,byte)
      Next
      Debug "Adapter : "+PeekS(@tempipinfo\Description)
      Debug "IP-Adress : "+PeekS(@tempipinfo\IpAddressList+4)
      Debug "Gateway : "+PeekS(@tempipinfo\GatewayList+4)
      mac$=""
      For i=0 To 5
        byte.b=PeekB(@tempipinfo\Address+i)
        If byte>=0
          mac$+RSet(Hex(byte),2,"0")
        Else
          mac$+RSet(Hex(byte+256),2,"0")
        EndIf
        If i<5
          mac$+":"
        EndIf
      Next
      Debug "MAC-Address "+mac$
    Next
  Else
    Debug "Error : "+Str(result)
  EndIf
EndIf
Voilà.
wolfjeremy
Messages : 1202
Inscription : sam. 31/déc./2005 23:52

Message par wolfjeremy »

Oui merci mais j'avais trouver, excuse j'ai oublier de marquer résolu :?
Répondre