Asp.net obtains the MAC address of the client.

Source: Internet
Author: User
Recently, a voting system has the following requirement: to prevent malicious canvassing or ticket refreshing, you must use the IP address of the remote client.

To obtain the MAC address of the client Nic. After finding a lot of materials at night, I finally got a little bit of information.

To obtain the MAC address of the NIC, you have to talk about the doscommand: NBTSTAT. The following is a brief introduction:
1. Specific functions

This command is used to display NetBIOS statistics, NetBIOS name table, and NetBIOS name cache for local and remote computers based on TCP/IP (netbt) protocols. NBTSTAT can refresh the NetBIOS name cache and the registered Windows Internet Name Service (WINS) Name. Use NBTSTAT without parameters to display help.

2. Syntax explanation

NBTSTAT [-A remotename] [-A IPaddress] [-C] [-N] [-R] [-R] [-rr] [-S] [-S] [interval]
3. parameter description

-A remotename: displays the NetBIOS name table of the remote computer. The remote name is the NetBIOS Name of the remote computer. The NetBIOS name table is a list of NetBIOS names used by applications running on the computer.
-A IPaddress: the NetBIOS name table of the remote computer is displayed. the NetBIOS name is specified by the IP address of the remote computer (separated by decimal places ).
-C: displays the NetBIOS name cache content, NetBIOS name table, and resolved addresses.
-N: displays the NetBIOS name table of the local computer. The status in registered indicates that the name is registered through a broadcast or WINS server.
-R displays statistics on NetBIOS name resolution. On a Windows computer configured to use wins, this parameter returns a name number that has been parsed and registered through broadcast and wins.
-R clears the content cached by NetBIOS Name and re-uploads a project with the # pre mark from the LmHosts file.
-Rr re-release and refresh the NetBIOS Name of the Local Computer registered through wins.
-S displays the NetBIOS client and server sessions and tries to convert the target IP address to a name.
-S displays the NetBIOS client and server sessions, and lists remote computers only through IP addresses.
Interval re-displays the selected statistics, which can interrupt the specified number of seconds in interval between each display. Press Ctrl + C to stop displaying statistics again. If this parameter is omitted, NBTSTAT displays the current configuration information only once.

Let's try its function: in the DOS window, enter:

NBTSTAT-A 192.168.168.242
Here 192.168.168.242 is my local IP address. During the test, the program that stays in the room cannot obtain a non-local MAC address. That is to say, only the nic mac address of the server can be obtained, instead, you cannot obtain the MAC address of the client Nic. Remember to use some hacker software to obtain the MAC address of the Peer Nic. The result is as follows:

Check the MAC address of the NIC! That is:

MAC address = 00-18-f3-a7-e1-56
Therefore, in Asp.net, we first obtain all the information of the specified IP address, and then use the regular expression to obtain the MAC address.

For details about the code, refer to the following. The Code has a reference network, which is used by me, not what I think.

Using system;
Using system. Data;
Using system. configuration;
Using system. Web;
Using system. Web. Security;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Web. UI. webcontrols. webparts;
Using system. Web. UI. htmlcontrols;

// Introduce the corresponding spatial information
Using system. Text. regularexpressions;
Using system. diagnostics;

Public partial class _ default: system. Web. UI. Page
{
Protected void page_load (Object sender, eventargs E)
{
// Enter the IP address here, and you can make it the value of the text box for query.
Response. Write (getcustomermac ("192.168.168.242 "));
}


// Here is the key function
Public String getcustomermac (string IP)
{
String dirresults = "";
Processstartinfo psi = new processstartinfo ();
Process proc = new process ();
PSI. filename = "NBTSTAT ";
PSI. redirectstandardinput = false;
PSI. redirectstandardoutput = true;
PSI. Arguments = "-a" + IP;
PSI. useshellexecute = false;
Proc = process. Start (PSI );
Dirresults = Proc. standardoutput. readtoend ();
Proc. waitforexit ();

// Match the MAC address
Match m = RegEx. match (dirresults, "\ W + \-\ W \ \ W ");

// If the match succeeds, the MAC address is returned; otherwise, the host information cannot be found.
If (M. tostring ()! = "")
{
Return M. tostring ();
}
Else
{
Return "host information not found ";
}

}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.