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">
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 sen Der, EventArgs e) {labName. text = labPass. text = "";} protected void getNamePass_Click (object sender, EventArgs e) {// obtain the Client IP address string IP = Request. userHostAddress; // create the string variable string dirResults = ""; // create the ProcessStartInfo object to indicate a set of values ProcessStartInfo psi = new ProcessStartInfo () used when starting the process (); // create a Process object so that you can start and stop the local system Process proc = new Process (); // set the application or document psi to be started. fileName = "nbtstat"; // set not from Process. Read input psi from StandardInput stream. redirectStandardInput = false; // you can specify the output to be written to the Process. standardOutput stream psi. redirectStandardOutput = true; // set a group of command parameters psi in the started application. arguments = "-A" + IP; // sets the psi process for creating A process from an executable file. useShellExecute = false; // set the startup Process proc = Process. start (psi); // obtain the StandardOutput output stream dirResults = proc. standardOutput. readToEnd (); // sets the Process component to wait for the associated Process to exit proc indefinitely. waitForExit (); // Replace "/r,/n ,/ T "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 the "MAC" string dirResults = dirResults + "MAC" to the obtained StandardOutput output stream; // obtain the Cookie HttpCookie oldCookie = Request. cookies ["netCard"]; // obtain the Match in the regular expression Match mc = reg. match (dirResults); // obtain the network card number to remove "-" and conform to string networkCard = mc. groups ["key"]. value. replace ("-", ""); // judge whether the Cookie is null if (oldCookie = null) {// determine whether the Cookie meets the regular expression requirements if (mc. success) {// display the account labName. Text = "your account is:" + networkCard; // display the password labPass. text = "Your password is: 1234"; // create the Cookie object HttpCookie newCookie = new HttpCookie ("netCard"); // set the Cookie validity period newCookie. expires = DateTime. maxValue; // Add the value newCookie in the Cookie. values. add ("numberCard", networkCard); // Add the Cookie to the Response in the Cookie set. cookies. add (newCookie);} else {RegisterStartupScript ("", "<script> alert ('you are not online! '); </Script> ") ;}} else {// obtain the nic id string numberCard = oldCookie in the Cookie. values ["numberCard"]; // determines 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 account labName. text = "your account is:" + networkCard; // display the password labPass. text = "your password: 1234"; // modify the value of oldCookie in the Cookie. values. set ("numberCard", networkCard); // Add the Cookie to the Response in the Cookie Set. cookies. add (oldCookie);} else {RegisterStartupScript ("", "<script> alert ('you are not online! '); </Script> ");}}}}}