Let's start with the following:
First, write a simple foreground code:
Copy Code code as follows:
<%@ Page language= "C #" autoeventwireup= "true" codefile= "Default.aspx.cs" inherits= "_default"%>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title> Untitled Page </title>
<body>
<form id= "Form1" runat= "Server" >
<div style= "Text-align:left" >
<strong><span style= "font-size:14pt" > Welcome to Love Wisdom Corner blog! </span><br/>
</strong><span style= "FONT-SIZE:10PT; Color: #ff0000 > Note: Only one account can be picked per computer <br/>
</span>
<asp:button id= "Getnamepass" runat= "Server" onclick= "Getnamepass_click" text= "Pick account password"/> <br
<asp:label id= "Labname" runat= "Server" ></asp:label><br/>
<asp:label id= "Labpass" runat= "Server" ></asp:label><br/>
</div>
</form>
</body>
Again to write a background code, remarks have been said more clearly, here is not much to say!
Copy Code code as follows:
Using System;
Using System.Data;
Using System.Configuration;
Using System.Collections;
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;
Using System.Text.RegularExpressions;
Using System.Diagnostics;
public partial class _default:system.web.ui.page
{
protected void Page_Load (object sender, EventArgs e)
{
Labname.text = Labpass.text = "";
}
protected void Getnamepass_click (object sender, EventArgs e)
{
Get the IP address of the client
string IP = request.userhostaddress;
To create a string variable
String dirresults = "";
Create a ProcessStartInfo object that represents a set of values to use when starting a process
ProcessStartInfo psi = new ProcessStartInfo ();
Creating a Process object enables you to start and stop Local system processes
Process proc = new process ();
Set up an application or document to start
Psi. FileName = "nbtstat";
Setting does not read input from the Process.standardinput stream
Psi. Redirectstandardinput = false;
Set to output write Process.standardoutput stream
Psi. Redirectstandardoutput = true;
Set a set of command parameters in a startup application
Psi. Arguments = "-A" + IP;
Setup to create a process from an executable file
Psi. UseShellExecute = false;
Setting up a startup process
proc = Process.Start (PSI);
Get StandardOutput output stream
Dirresults = Proc. Standardoutput.readtoend ();
To set the process component to wait indefinitely for the associated process to exit
Proc. WaitForExit ();
Replace the "/r,/n,/t" in the StandardOutput output stream
Dirresults = Dirresults.replace ("\ R", ""). Replace ("\ n", ""). Replace ("T", "");
Set Regular expression
Regex reg = new Regex ("mac[]{0,}address[]{0,}=[]{0,}" (?<key> (.) *?)) MAC ", Regexoptions.ignorecase | regexoptions.compiled);
Adds a "MAC" string to the fetched StandardOutput output stream
Dirresults = dirresults + "MAC";
Get cookies
HttpCookie Oldcookie = request.cookies["netcard"];
Get a match in a regular expression
Match MC = Reg. Match (Dirresults);
Get the NIC number to get rid of "-" compliant
String Networkcard = mc. groups["Key"]. Value.replace ("-", "");
To determine whether a cookie is empty
if (Oldcookie = null)
{
To determine whether the regular expression meets the requirements
if (MC. Success)
{
Show account number
Labname.text = "Your account number is:" + networkcard;
Display password
Labpass.text = "Your password is: 1234";
Creating a Cookie Object
HttpCookie Newcookie = new HttpCookie ("netcard");
Set the valid time for cookies
Newcookie.expires = DateTime.MaxValue;
Add a value in a cookie
NEWCOOKIE.VALUES.ADD ("Numbercard", Networkcard);
Adding cookies to the cookie collection
RESPONSE.COOKIES.ADD (Newcookie);
}
Else
{
RegisterStartupScript ("", "<script>alert") (' You don't have a network! ');</script> ");
}
}
Else
{
Get the network card number in the cookie
String numbercard = oldcookie.values["Numbercard"];
Determine if the network card number in the cookie is the same as the NIC number obtained
if (numbercard.trim () = = Networkcard.trim ())
{
RegisterStartupScript ("", "<script>alert") (' Sorry! Your computer has already received an account number. ') </script> ");
}
Else
{
To determine whether the regular expression meets the requirements
if (MC. Success)
{
Show account number
Labname.text = "Your account number is:" + networkcard;
Display password
Labpass.text = "Your password is: 1234";
Modify a value in a cookie
OldCookie.Values.Set ("Numbercard", Networkcard);
Adding cookies to the cookie collection
RESPONSE.COOKIES.ADD (Oldcookie);
}
Else
{
RegisterStartupScript ("", "<script>alert") (' You don't have a network! ');</script> ");
}
}
}
}
}