Here is only a simple demonstration process. Please modify it based on your actual situation!
In addition, my blog is only easy to use for your own reference query. Please do not spray me with your skills. I am a newbie studying hard. Thank you !!!!
Start now:
First, write a simple front-end code:
<% @ 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">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> No title page </title>
</Head>
<Body>
<Form id = "form1" runat = "server">
<Div style = "text-align: left">
<Strong> <span style = "font-size: 14pt"> welcome to the blog of AI zhixiao! </Span> <br/>
</Strong> <span style = "font-size: 10pt; color: # ff0000"> Note: each computer can only receive one account <br/>
</Span>
<Asp: Button ID = "getNamePass" runat = "server" OnClick = "getNamePass_Click" Text = "Get account password"/> & nbsp; <br/>
<Asp: Label ID = "labName" runat = "server"> </asp: Label> <br/>
<Asp: Label ID = "labPass" runat = "server"> </asp: Label> <br/>
</Div>
</Form>
</Body>
</Html>
Let's write another background code. The remarks are clear and I will not talk about them here!
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)
{
// Obtain the Client IP Address
String IP = Request. UserHostAddress;
// Create a string variable
String dirResults = "";
// Create a ProcessStartInfo object to indicate a group of values used when the process is started
ProcessStartInfo psi = new ProcessStartInfo ();
// Create a Process object so that you can start and stop local system processes
Process proc = new Process ();
// Set the application or document to be started
Psi. FileName = "nbtstat ";
// The setting does not read the input from the Process. StandardInput stream.
Psi. RedirectStandardInput = false;
// Set the Process. StandardOutput stream for output writing
Psi. RedirectStandardOutput = true;
// Set a group of command parameters in the started Application
Psi. Arguments = "-A" + IP;
// Set the process to be created from an executable file
Psi. UseShellExecute = false;
// Set the startup process www.2cto.com
Proc = Process. Start (psi );
// Obtain the StandardOutput output stream
DirResults = proc. StandardOutput. ReadToEnd ();
// Set the Process component to wait for the associated Process to exit indefinitely
Proc. WaitForExit ();
// Replace "/r,/n,/t" in the output stream of StandardOutput"
DirResults = dirResults. Replace ("\ r", ""). Replace ("\ n", ""). Replace ("\ t ","");
// Set the Regular Expression
Regex reg = new Regex ("MAC [] {0,} Address [] {0,} = [] {0 ,}(? <Key> ((.)*?)) MAC ", RegexOptions. IgnoreCase | RegexOptions. Compiled );
// Add a "MAC" string to the obtained StandardOutput output stream
DirResults = dirResults + "MAC ";
// Obtain the Cookie
HttpCookie oldCookie = Request. Cookies ["netCard"];
// Obtain the matching items in the Regular Expression
Match mc = reg. Match (dirResults );
// Obtain the nic id to remove "-".
String networkCard = mc. Groups ["key"]. Value. Replace ("-","");
// Determine whether the Cookie is null
If (oldCookie = null)
{
// Determine whether the regular expression meets the requirements
If (mc. Success)
{
// Display the account
LabName. Text = "your account is:" + networkCard;
// Display Password
LabPass. Text = "Your password is 1234 ";
// Create a Cookie object
HttpCookie newCookie = new HttpCookie ("netCard ");
// Set the Cookie Validity Period
NewCookie. Expires = DateTime. MaxValue;
// Add the Cookie value
NewCookie. Values. Add ("numberCard", networkCard );
// Add the Cookie to the Cookie set
Response. Cookies. Add (newCookie );
}
Else
{
RegisterStartupScript ("", "<script> alert ('you are not connected to the internet! '); </Script> ");
}
}
Else
{
// Obtain the nic id in the Cookie
String numberCard = oldCookie. Values ["numberCard"];
// Determine whether the nic id in the Cookie is consistent with the obtained Nic ID
If (numberCard. Trim () = networkCard. Trim ())
{
RegisterStartupScript ("", "<script> alert ('sorry! Your computer has obtained an account. ') </Script> ");
}
Else
{
// Determine whether the regular expression meets the requirements
If (mc. Success)
{
// Display the account
LabName. Text = "your account is:" + networkCard;
// Display Password
LabPass. Text = "Your password is 1234 ";
// Modify the Cookie value
OldCookie. Values. Set ("numberCard", networkCard );
// Add the Cookie to the Cookie set
Response. Cookies. Add (oldCookie );
}
Else
{
RegisterStartupScript ("", "<script> alert ('you are not connected to the internet! '); </Script> ");
}
}
}
}
}
From Ai Zhi Chen