国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

asp.net根據計算機MAC地址限定每臺機子只能領取一次賬號

2020-01-18 00:28:59
字體:
來源:轉載
供稿:網友
下面開始吧:
首先寫一個簡單的前臺代碼:
復制代碼 代碼如下:

<%@ 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>無標題頁</title>
</head>
<body>
<form id="form1" runat="server">
<div style="text-align: left">
<strong><span style="font-size: 14pt">歡迎光臨愛智旮旯的博客!</span><br />
</strong><span style="font-size: 10pt; color: #ff0000">注:每臺計算機只可以領取一個帳號<br />
</span>
<asp:Button ID="getNamePass" runat="server" OnClick="getNamePass_Click" Text="領取帳號密碼" /> <br />
<asp:Label ID="labName" runat="server"></asp:Label><br />
<asp:Label ID="labPass" runat="server"></asp:Label><br />
</div>
</form>
</body>
</html>

再來寫一個后臺代碼,備注已經說的比較清楚,這里不多說了!
復制代碼 代碼如下:

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)
{
//獲取客戶端的IP地址
string IP = Request.UserHostAddress;
//創建字符串變量
string dirResults = "";
//創建ProcessStartInfo對象表示啟動進程時使用的一組值
ProcessStartInfo psi = new ProcessStartInfo();
//創建Process對象使您能夠啟動和停止本地系統進程
Process proc = new Process();
//設置要啟動的應用程序或文檔
psi.FileName = "nbtstat";
//設置不從Process.StandardInput流中讀取輸入
psi.RedirectStandardInput = false;
//設置要輸出寫入 Process.StandardOutput流
psi.RedirectStandardOutput = true;
//設置啟動的應用程序中的一組命令參數
psi.Arguments = "-A " + IP;
//設置從可執行文件創建進程
psi.UseShellExecute = false;
//設置啟動進程
proc = Process.Start(psi);
//獲取StandardOutput輸出流
dirResults = proc.StandardOutput.ReadToEnd();
//設置Process 組件無限期地等待關聯進程退出
proc.WaitForExit();
//替換掉StandardOutput輸出流中的"/r,/n,/t"
dirResults = dirResults.Replace("/r", "").Replace("/n", "").Replace("/t", "");
//設置正則表達式
Regex reg = new Regex("MAC[ ]{0,}Address[ ]{0,}=[ ]{0,}(?<key>((.)*?))MAC", RegexOptions.IgnoreCase | RegexOptions.Compiled);
//向獲取的StandardOutput輸出流添加"MAC"字符串
dirResults = dirResults + "MAC";
//獲取Cookie
HttpCookie oldCookie = Request.Cookies["netCard"];
//獲取正則表達式中的匹配項
Match mc = reg.Match(dirResults);
//獲取網卡號去除掉“-”符合
string networkCard = mc.Groups["key"].Value.Replace("-", "");
//判斷Cookie是否為空
if (oldCookie == null)
{
//判斷是否符合正則表達式的要求
if (mc.Success)
{
//顯示帳號
labName.Text = "您的帳號為:" + networkCard;
//顯示密碼
labPass.Text = "您的密碼為:1234";
//創建Cookie對象
HttpCookie newCookie = new HttpCookie("netCard");
//設置Cookie的有效時間
newCookie.Expires = DateTime.MaxValue;
//添加Cookie中的值
newCookie.Values.Add("numberCard", networkCard);
//將Cookie添加到Cookie集合中
Response.Cookies.Add(newCookie);
}
else
{
RegisterStartupScript("", "<script>alert( '您沒有聯網!');</script>");
}
}
else
{
//獲取Cookie中的網卡號
string numberCard = oldCookie.Values["numberCard"];
//判斷Cookie中的網卡號是否和獲取到的網卡號一致
if (numberCard.Trim() == networkCard.Trim())
{
RegisterStartupScript("", "<script>alert('很抱歉!您的計算機已領取過帳號。')</script>");
}
else
{
//判斷是否符合正則表達式的要求
if (mc.Success)
{
//顯示帳號
labName.Text = "您的帳號為:" + networkCard;
//顯示密碼
labPass.Text = "您的密碼為:1234";
//修改Cookie中的值
oldCookie.Values.Set("numberCard", networkCard);
//將Cookie添加到Cookie集合中
Response.Cookies.Add(oldCookie);
}
else
{
RegisterStartupScript("", "<script>alert( '您沒有聯網!');</script>");
}
}
}
}
}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 鞍山市| 和硕县| 盐池县| 南平市| 鄂州市| 关岭| 如东县| 宜阳县| 常宁市| 若尔盖县| 乡城县| 得荣县| 信宜市| 响水县| 耿马| 大连市| 富顺县| 西丰县| 平安县| 老河口市| 扎赉特旗| 泽州县| 东源县| 平塘县| 吉隆县| 南涧| 海淀区| 文昌市| 西吉县| 山西省| 图片| 碌曲县| 镇巴县| 麟游县| 乐陵市| 鄂托克前旗| 东莞市| 米脂县| 永年县| 沂南县| 鸡西市|