MAC-Adresse der Netzwerkkarten



  • Hallo,

    weiss jemand ob die MAC-Adresse(n) in der Registry steht.
    Die IP-Adresse(n) habe ich dort gefunden.

    Danke
    Mikel





  • @paranoiac.org
    ist ja ganz net, nur das war nicht die Frage.

    Wie ich die MAC über SMTP ermittle ist mir klar. Ich will aber wissen ob sie wie die IP auch in der Registry steht.

    Danke Mikel



  • Ok! Dann tuts mir leid.
    Ich hätte ein Programm fuer dich, allerdings in VBasic, dass die MAC ausließt.
    Hab keine Zeit es umzuschreiben, wuerde es vielleicht au net schaffen...

    Hier der Code:

    Option Explicit
    
    Private Declare Function Netbios Lib "netapi32.dll" _
            (pncb As NCB) As Byte
    
    Private Declare Sub CopyMemory Lib "kernel32" Alias _
            "RtlMoveMemory" (hpvDest As Any, ByVal hpvSource _
            As Long, ByVal cbCopy As Long)
    
    Private Declare Function GetProcessHeap Lib "kernel32" () _
            As Long
    
    Private Declare Function HeapAlloc Lib "kernel32" (ByVal _
            hHeap As Long, ByVal dwFlags As Long, ByVal dwBytes _
            As Long) As Long
    
    Private Declare Function HeapFree Lib "kernel32" (ByVal hHeap _
            As Long, ByVal dwFlags As Long, lpMem As Any) As Long
    
    Const NCBASTAT = &H33
    Const NCBNAMSZ = 16
    Const HEAP_ZERO_MEMORY = &H8
    Const HEAP_GENERATE_EXCEPTIONS = &H4
    Const NCBRESET = &H32
    
    Private Type NCB
      ncb_command As Byte
      ncb_retcode As Byte
      ncb_lsn As Byte
      ncb_num As Byte
      ncb_buffer As Long
      ncb_length As Integer
      ncb_callname As String * NCBNAMSZ
      ncb_name As String * NCBNAMSZ
      ncb_rto As Byte
      ncb_sto As Byte
      ncb_post As Long
      ncb_lana_num As Byte
      ncb_cmd_cplt As Byte
      ncb_reserve(9) As Byte
      ncb_event As Long
    End Type
    
    Private Type ADAPTER_STATUS
      adapter_address(5) As Byte
      rev_major As Byte
      reserved0 As Byte
      adapter_type As Byte
      rev_minor As Byte
      duration As Integer
      frmr_recv As Integer
      frmr_xmit As Integer
      iframe_recv_err As Integer
      xmit_aborts As Integer
      xmit_success As Long
      recv_success As Long
      iframe_xmit_err As Integer
      recv_buff_unavail As Integer
      t1_timeouts As Integer
      ti_timeouts As Integer
      Reserved1 As Long
      free_ncbs As Integer
      max_cfg_ncbs As Integer
      max_ncbs As Integer
      xmit_buf_unavail As Integer
      max_dgram_size As Integer
      pending_sess As Integer
      max_cfg_sess As Integer
      max_sess As Integer
      max_sess_pkt_size As Integer
      name_count As Integer
    End Type
    
    Private Type NAME_BUFFER
      name As String * NCBNAMSZ
      name_num As Integer
      name_flags As Integer
    End Type
    
    Private Type ASTAT
      adapt As ADAPTER_STATUS
      NameBuff(30) As NAME_BUFFER
    End Type
    
    Private Sub Form_Load()
      Dim myNcb As NCB
      Dim bRet As Byte
      Dim myASTAT As ASTAT, tempASTAT As ASTAT
      Dim pASTAT As Long
    
        myNcb.ncb_command = NCBRESET
        bRet = Netbios(myNcb)
        myNcb.ncb_command = NCBASTAT
        myNcb.ncb_lana_num = 0
        myNcb.ncb_callname = "* "
    
        myNcb.ncb_length = Len(myASTAT)
    
        pASTAT = HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS _
                 Or HEAP_ZERO_MEMORY, myNcb.ncb_length)
    
        If pASTAT = 0 Then Exit Sub
    
        myNcb.ncb_buffer = pASTAT
        bRet = Netbios(myNcb)
    
        CopyMemory myASTAT, myNcb.ncb_buffer, Len(myASTAT)
        Label1.Caption = _
                   HexEx(myASTAT.adapt.adapter_address(0)) & "-" & _
                   HexEx(myASTAT.adapt.adapter_address(1)) & "-" & _
                   HexEx(myASTAT.adapt.adapter_address(2)) & "-" & _
                   HexEx(myASTAT.adapt.adapter_address(3)) & "-" & _
                   HexEx(myASTAT.adapt.adapter_address(4)) & "-" & _
                   HexEx(myASTAT.adapt.adapter_address(5))
    
        Call HeapFree(GetProcessHeap(), 0, pASTAT)
    End Sub
    
    Private Function HexEx(ByVal B&) As String
      Dim aa$
    
        aa = Hex(B)
        If Len(aa) < 2 Then aa = "0" & aa
        HexEx = aa
    End Function
    

    cu para
    😃



  • OK!
    Dass wir dann vielleicht was für die FAQ hätten (@mod) 😮

    #include <windows.h>
    #include <stdlib.h>
    #include <stdio.h>
    #include <iostream>
    #include <strstream>
    #include <string>
    
    using namespace std;
    
    bool GetAdapterInfo(int nAdapterNum, string & sMAC)
    {
        // Reset the LAN adapter so that we can begin querying it 
        NCB Ncb;
        memset(&Ncb, 0, sizeof(Ncb));
        Ncb.ncb_command = NCBRESET;
        Ncb.ncb_lana_num = nAdapterNum;
        if (Netbios(&Ncb) != NRC_GOODRET) {
            char acTemp[80];
            ostrstream outs(acTemp, sizeof(acTemp));
            outs << "error " << Ncb.ncb_retcode << " on reset" << ends;
            sMAC = acTemp;
            return false;
        }
    
        // Prepare to get the adapter status block 
        memset(&Ncb, 0, sizeof(Ncb));
        Ncb.ncb_command = NCBASTAT;
        Ncb.ncb_lana_num = nAdapterNum;
        strcpy((char *) Ncb.ncb_callname, "*");
        struct ASTAT {
            ADAPTER_STATUS adapt;
            NAME_BUFFER NameBuff[30];
        } Adapter;
        memset(&Adapter, 0, sizeof(Adapter));
        Ncb.ncb_buffer = (unsigned char *)&Adapter;
        Ncb.ncb_length = sizeof(Adapter);
    
        // Get the adapter's info and, if this works, return it in standard,
        // colon-delimited form.
        if (Netbios(&Ncb) == 0) {
            char acMAC[18];
            sprintf(acMAC, "%02X:%02X:%02X:%02X:%02X:%02X",
                    int (Adapter.adapt.adapter_address[0]),
                    int (Adapter.adapt.adapter_address[1]),
                    int (Adapter.adapt.adapter_address[2]),
                    int (Adapter.adapt.adapter_address[3]),
                    int (Adapter.adapt.adapter_address[4]),
                    int (Adapter.adapt.adapter_address[5]));
            sMAC = acMAC;
            return true;
        }
        else {
            char acTemp[80];
            ostrstream outs(acTemp, sizeof(acTemp));
            outs << "error " << Ncb.ncb_retcode << " on ASTAT" << ends;
            sMAC = acTemp;
            return false;
        }
    }
    
    int main()
    {
        // Get adapter list
        LANA_ENUM AdapterList;
        NCB Ncb;
        memset(&Ncb, 0, sizeof(NCB));
        Ncb.ncb_command = NCBENUM;
        Ncb.ncb_buffer = (unsigned char *)&AdapterList;
        Ncb.ncb_length = sizeof(AdapterList);
        Netbios(&Ncb);
    
        // Get all of the local ethernet addresses
        string sMAC;
        for (int i = 0; i < AdapterList.length; ++i) {
            if (GetAdapterInfo(AdapterList.lana[i], sMAC)) {
                cout << "Adapter " << int (AdapterList.lana[i]) <<
                        "'s MAC is " << sMAC << endl;
            }
            else {
                cerr << "Failed to get MAC address! Do you" << endl;
                cerr << "have the NetBIOS protocol installed?" << endl;
                break;
            }
        }
    
        return 0;
    }
    

    cu para
    😃



  • @paranoiac.org
    ist ja ganz net, nur das war immer noch nicht meine Frage. 😉
    Außerdem hat deine Lösung den kleinen Schönheitsfehler das NetBios installiert sein muss.

    cerr << "Failed to get MAC address! Do you" << endl;
    cerr << "have the NetBIOS protocol installed?" << endl;

    Dann schon besser die Lösung über SMNP die du im ersten Post gelinkt hast. Im selben Tut ist übrigens auch die Lösung per NetBios und noch eine dritte Alternative vorhanden.

    Hier nochmal meine Frage:
    Steht die MAC-Adresse in der Registry ?

    Gruß Mikel



  • Ja.

    HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/<my_board>/Parameters/



  • @Crest
    Danke, aber ich finde den Eintrag nicht. 😞
    Mit welcher Windowsversion arbeitest du ?

    Gruß Mikel


Anmelden zum Antworten