Network Card Information Program

Experimental requirements

1. Display network card information
2. Display IPV4 information

Experimental steps

1. Functions of Confirmation Program

Query all network card information on the computer, including network card name, MAC address, IP address, sub-gateway mask, gateway and other information

2. Searching for Relevant Information on the Internet

Understand that local network information can be obtained by calling `GetAdaptersInfo()'and stored in the structure `pAdapterInfo'.

3. Design of Program Interface by MFC

All network cards are displayed by dropping down the CompoBox of the local network card. Select one of the network cards and press the "confirm" button for query. The corresponding information of the network card is displayed in the edit box below.

4. Setting Control Variables
Variable settings for controls in dialog boxes to display information queried by programs

5. Mapping Network Card Information
pAdapterInfo records the network card information in the form of a linked list, and traverses the pAdapter to display the description of the network card (which is easier to identify than the network card number) into ComboBox (through ComboBox variables).

pAdapter = pAdapterInfo;
if (i < 1) {
        while (pAdapter) {
            //combo.AddString((LPCTSTR)pAdapter->AdapterName);
            //CString str=pAdapter->AdapterName;
            CString str;
            //str=pAdapter->AdapterName.toString();

            str = pAdapter->Description;
            //str.Format(_T("%s"), pAdapter->AdapterName);
            combo.AddString(str);
            pAdapter = pAdapter->Next;
        }
        i++;
    }

6. Selecting Network Card Function
Get the description of the currently selected network card and match it with all network cards to find the items corresponding to the pAdapter list

CString strstatus;      //Define a string variable
combo.GetLBText(nSel, strstatus);    //Assign the value of the current cursor to a variable
while(pAdapter->Description != strstatus)//Match to find the corresponding network card
pAdapter = pAdapter->Next;

7. Display corresponding network card information
Display the information of the selected network card on the corresponding Exit Control

When displaying the MAC address, because the MAC address is stored in binary system, it is necessary to convert the binary system into hexadecimal system, and then to store the corresponding characters.

void Cnetcard_messageDlg::OnBnClickedOk()
{
    // TODO: Add control notification handler code here
    // TODO: Add control notification handler code here
    int nSel;
    CString cstr1;
    CString cstr2;
    CString cstr3;
    CString cstr4;
    CString cstr5;
    char temp[8] = "";
    int int_temp;
    PIP_ADAPTER_INFO pAdapter;  //*IP_ADAPTER_INFO
    pAdapter = pAdapterInfo;
    // Gets the index of the selected item in the list box of the combo box control
    nSel = combo.GetCurSel();
    CString strstatus;      //Define a string variable
    combo.GetLBText(nSel, strstatus);    //Assign the value of the current cursor to a variable
    while(pAdapter->Description != strstatus)
        pAdapter = pAdapter->Next;
    cstr1 = pAdapter->AdapterName;              //NIC card number
    for (i = 0; i < pAdapter->AddressLength; ++i) 
    {
        int_temp = (int)pAdapter->Address[i];
        _itoa_s(int_temp, temp, 4, 16);//The number represented by int_temp is converted to the character array temp of length 4 in hexadecimal
        if (int_temp == 0)
                temp[0] = temp[1] = '0';//XX-00-XX needs to be displayed when int_temp is 0
        cstr2 += temp;//Connect characters to full strings
        if (i+1 < pAdapter->AddressLength)
            cstr2 += '-';
    }
    //(pAdapter->Address[i]).ToString();
    cstr3 = pAdapter->IpAddressList.IpAddress.String;   //IP
    cstr4 = pAdapter->IpAddressList.IpMask.String;      //Child pass mask
    cstr5 = pAdapter->GatewayList.IpAddress.String;     //gateway
    // Gets the string based on the index of the selected item
    //combo.GetLBText(nSel, cstr);
    // Display the selected string in the combo box to the IDC_SEL_WEB_EDIT edit box
    SetDlgItemText(IDC_EDIT1, cstr1);   //adapter name
    SetDlgItemText(IDC_EDIT2, cstr2);   //MAC address
    SetDlgItemText(IDC_EDIT3, cstr3);   //IP address
    SetDlgItemText(IDC_EDIT4, cstr4);   //Subnet mask
    SetDlgItemText(IDC_EDIT5, cstr5);   //gateway

    //getchar();
}

So far, the small program for displaying network card information has been completed.

Full Function Display

Keywords: network Mac

Added by KCKTechs on Mon, 20 May 2019 04:20:33 +0300