asp.net limits each machine to one account per machine based on the MAC address
- 2020-05-17 05:09:58
- OfStack
Here we go:
First, write a simple foreground code:
To write a background code, note has said more clearly, here do not say!
First, write a simple foreground 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 aizhigala! </span><br />
</strong><span style="font-size: 10pt; color: #ff0000"> Note: each computer is available for collection only 1 An account <br />
</span>
<asp:Button ID="getNamePass" runat="server" OnClick="getNamePass_Click" Text=" Get the account password " /> <br />
<asp:Label ID="labName" runat="server"></asp:Label><br />
<asp:Label ID="labPass" runat="server"></asp:Label><br />
</div>
</form>
</body>
</html>
To write a background code, note has said more clearly, here do not say!
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)
{
// Capture client IP address
string IP = Request.UserHostAddress;
// Create a string variable
string dirResults = "";
// create ProcessStartInfo Object that is used to start the process 1 Set of values
ProcessStartInfo psi = new ProcessStartInfo();
// create Process Object enables you to start and stop local system processes
Process proc = new Process();
// Sets the application or document to launch
psi.FileName = "nbtstat";
// Don't set from Process.StandardInput The input is read in the stream
psi.RedirectStandardInput = false;
// Sets the output to be written Process.StandardOutput flow
psi.RedirectStandardOutput = true;
// Sets the startup in the application 1 Group command parameter
psi.Arguments = "-A " + IP;
// Set up the create process from the executable
psi.UseShellExecute = false;
// Set up the startup process
proc = Process.Start(psi);
// To obtain StandardOutput The output stream
dirResults = proc.StandardOutput.ReadToEnd();
// Set up the Process The component waits indefinitely for the associated process to exit
proc.WaitForExit();
// replace StandardOutput In the output stream "/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);
// To obtain the StandardOutput Output stream addition "MAC" string
dirResults = dirResults + "MAC";
// To obtain Cookie
HttpCookie oldCookie = Request.Cookies["netCard"];
// Gets a match in a regular expression
Match mc = reg.Match(dirResults);
// Get rid of network card number" - "In accordance with
string networkCard = mc.Groups["key"].Value.Replace("-", "");
// judge Cookie Whether is empty
if (oldCookie == null)
{
// Determine if the requirements of the regular expression are met
if (mc.Success)
{
// According to the account
labName.Text = " Your account number is: " + networkCard;
// Show the password
labPass.Text = " Your password is: 1234";
// create Cookie object
HttpCookie newCookie = new HttpCookie("netCard");
// Set up the Cookie Effective time
newCookie.Expires = DateTime.MaxValue;
// add Cookie The values in the
newCookie.Values.Add("numberCard", networkCard);
// will Cookie Added to the Cookie In the collection
Response.Cookies.Add(newCookie);
}
else
{
RegisterStartupScript("", "<script>alert( ' You are not connected to the Internet! ');</script>");
}
}
else
{
// To obtain Cookie Network card number
string numberCard = oldCookie.Values["numberCard"];
// judge Cookie Whether the network card number and get the network card number 1 to
if (numberCard.Trim() == networkCard.Trim())
{
RegisterStartupScript("", "<script>alert(' I'm sorry! Your computer has received an account. ')</script>");
}
else
{
// Determine if the requirements of the regular expression are met
if (mc.Success)
{
// According to the account
labName.Text = " Your account number is: " + networkCard;
// Show the password
labPass.Text = " Your password is: 1234";
// Modify the Cookie The values in the
oldCookie.Values.Set("numberCard", networkCard);
// will Cookie Added to the Cookie In the collection
Response.Cookies.Add(oldCookie);
}
else
{
RegisterStartupScript("", "<script>alert( ' You are not connected to the Internet! ');</script>");
}
}
}
}
}