-_-没什么好说的了吧!之前写了个JSP的 现在找个ASPX的实现了!还给自己一个心愿~~
说起来也真头疼ASPX跟JSP/SERVLET的生命周期 不一样~ ASPX页面的对象浏览完了自动会销毁...而JSP/SERLVET的是通过容器反射调用 对象的service方法~所以页面的成员属性不会释放!ASPX则不同了!所以没办法只能使用类里面的静态成员靠!先看看下面图片吧!
代码如下:
-----------------------------------------
<%@ Page Language="C#" AutoEventWireup="true" %>
<%@ Import Namespace="System.Collections" %>
<%@ Import Namespace="System.Threading" %>
<%@ Import Namespace="System.Net.Sockets" %>
<script runat="server">
//author : kj021320(nonamed)
//blog : http://blog.csdn.net/kj021320/
static ArrayList threadScheduler = new ArrayList();//JOB Scheduler
public class JobConsole
{
public ArrayList subThreadsPool = new ArrayList();//sub Threads pool
public int startPort;//开始端口
public int port;//循环端口
public int endPort;//结束端口
public int state = 0;//0进行 1暂停 2停止
public string host;//IP地址
public string errMsg = "";//错误信息
public StringBuilder succMsg = new StringBuilder();//成功信息
public int threadCount = 0;
public void start()
{
for (int c = 1; c <= threadCount; c++)
{
Thread thread = new Thread(new ThreadStart(this.run));
subThreadsPool.Add(thread);
thread.Start();
thread = null;
}
}
//启动线程
public void run()
{
int localPort = 0;
while (localPort <= endPort)
{
while (state == 1) { Thread.Sleep(5000);}
if (state == 2) { return; }
lock (this) { localPort = port++; }
try
{
TcpClient tcpClient = new TcpClient();
tcpClient.Connect(host, localPort);
lock (succMsg)
{
succMsg.Append(localPort + ",");
}
tcpClient.Close();
}
catch (SocketException se)
{
if (se.ErrorCode == 10051 || se.ErrorCode == 10052 || se.ErrorCode == 10014)
{
this.state = 2;
}
errMsg = se.Message;
}
}
state = 2;
}
}
</script>
<%
String action=Request.QueryString["Action"];
if (action!=null && !"".Equals(action)) {
if("AddToScan".Equals(action))
{
string host = Request.QueryString["host"];//取得主机名字
string port = Request.QueryString["port"];//取得开始port
string endPort = Request.QueryString["endPort"];//取得结束port
string thread = Request.QueryString["thread"];//取得线程
JobConsole jc = new JobConsole();
jc.host = host;
jc.port = Convert.ToInt32(port);
jc.startPort = jc.port;
jc.endPort = Convert.ToInt32(endPort);
jc.threadCount = Convert.ToInt32(thread);
threadScheduler.Add(jc);
jc.start();
jc = null;
}else if ("del".Equals(action))
{
string id = Request.QueryString["id"];
if (id != null)
{
int num = Convert.ToInt32(id);
JobConsole jc = (JobConsole)threadScheduler[num];
jc.state = 2;//更改状态为stop
threadScheduler.RemoveAt(num);//移除集合里面的对象
jc.subThreadsPool.Clear();//清楚线程池里面的所有线程
jc = null;
}
}
else if ("Run".Equals(action))
{
string id = Request.QueryString["id"];
if(id!=null)
{
int num = Convert.ToInt32(id);
JobConsole jc = (JobConsole)threadScheduler[num];
jc.state = 0;//running 状态
jc.port = jc.startPort;
jc.start();//重新开始
jc = null;
}
}
else if ("Pause".Equals(action))
{
string id = Request.QueryString["id"];
if (id != null)
{
int num = Convert.ToInt32(id);
JobConsole jc = (JobConsole)threadScheduler[num];
jc.state = 1;//pause 状态
jc = null;
}
}else if ("Continue".Equals(action))
{
string id = Request.QueryString["id"];
if (id != null)
{
int num = Convert.ToInt32(id);
JobConsole jc = (JobConsole)threadScheduler[num];
jc.state = 0;//running 状态
jc = null;
}
}else
{
Response.Write("<TABLE><TR><TD>JOB</TD><TD>THREAD</TD><TD>STATE</TD><TD>HOST</TD><TD>SCANNING...</TD><TD>END PORT</TD><TD>SUCC MSG</TD><TD>ERR MSG</TD><TD>ACTION</TD></TR>");
int count=threadScheduler.Count;
for(int i=0;i<count;i++){
threadScheduler.TrimToSize();
JobConsole jc=(JobConsole)threadScheduler[i];
String scanState="";
String operate="";
if(jc!=null)
{
switch(jc.state){
case 0:scanState="running";operate="<input type=button value=Pause οnclick=/"ThreadOperate('Pause',"+i+")/">";break;
case 1:scanState="pause";operate="<input type=button value=Continue οnclick=/"ThreadOperate('Continue',"+i+")/">";break;
case 2:scanState="stop";operate="<input type=button value=Run οnclick=/"ThreadOperate('Run',"+i+")/">";break;
}
Response.Write("<TR><TD>"+i+"</TD><TD>"+jc.threadCount+"</TD>");
Response.Write("<TD>"+scanState+"</TD><TD>"+jc.host+"</TD><TD>"+(jc.port-1)+"</TD><TD>"+jc.endPort+"</TD>");
Response.Write("<TD>"+jc.succMsg+"</TD><TD>"+jc.errMsg+"</TD><TD><input type=button value=Drop οnclick='DropThread("+i+");'>"+operate+"</TD></TR>");
jc=null;
}
}
Response.Write("<TR><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD></TR></TABLE>");
}
GC.Collect();
Response.End();
return;
}
%>
<html xmlns:v="urn:schemas-microsoft-com:vml">
<head>
<title>ISTO Extreme .NETScanning 1.0</title>
<style type="text/css">
v/:*{behavior:url(#default#VML);position:absolute;}
body,td{font-size: 12px;}
body,td{font-size:12px;}
table{T:expression(this.border='1',this.borderColorLight='Black',this.borderColorDark='White');}
input,select{font-size:12px;color:#000000;}
input{border-color:"#000000";color:#008800;background-color:#333333;}
body{margin-left:0px;margin-top:0px;margin-right:0px;margin-bottom:0px;}
td{white-space:nowrap;}
a{color:black;text-decoration:none; color:#008800;}
</style>
<script language="javascript">
//common
String.prototype.trim = function()
{
return this.replace(/(^/s*)|(/s*$)/g, "");
}
String.prototype.ltrim = function()
{
return this.replace(/(^/s*)/g, "");
}
String.prototype.rtrim = function()
{
return this.replace(/(/s*$)/g, "");
}
function createXmlHttpRequest(){//create AJAX CONSOLES
if(window.ActiveXObject){
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}else if(window.XMLHttpRequst){
xmlHttp=new XMLHttpRequst();
}
}
//ref需要信息的组件
function getTheMessage(ref){
if(xmlHttp.readyState==4){
if(xmlHttp.status==200){
var replaceStr;
replaceStr=xmlHttp.responseText;
replaceStr=replaceStr.trim();
if(replaceStr!=""&&ref){
ref.innerHTML=replaceStr;
}
return replaceStr;
}else{
return "";
}
}else{
return "";
}
}
//str:connection HTTP URL
//code:eval the code
function openUrlXmlHttpRequstEval(str,code){
url=str;
createXmlHttpRequest();
xmlHttp.open("get",url,true);
xmlHttp.onreadystatechange=function tmp(){eval(code);};
xmlHttp.send();
}
//str:connection HTTP URL
//ref:replace the HTML consoles
function openUrlXmlHttpRequstReplace(str,ref){
url=str;
createXmlHttpRequest();
xmlHttp.open("get",url,true);
xmlHttp.onreadystatechange=function tmp(){getTheMessage(ref);};
xmlHttp.send();
}
</script>
<script language="javascript">
//user define functions
//add to scan
function post(){
if(S.host.value!=""){
if(!isNaN(S.endPort.value)&&parseInt(S.endPort.value)<=65535){
if(!isNaN(S.port.value)&&parseInt(S.port.value)<=parseInt(S.endPort.value)&&parseInt(S.port.value)>0){
var url="?Action=AddToScan&host="+S.host.value+"&thread="+S.thread.value+"&port="+S.port.value+"&endPort="+S.endPort.value+"&"+Math.random();
openUrlXmlHttpRequstEval(url,"");S.port.value="";
S.host.value="";S.endPort.value="";
alert("add success");
}else{
alert("set start port error");
}
}else{
alert("set end port error");
}
}else{
alert("HOST can't empty");
}
}
//view pool
function viewSchedulerPool(){
openUrlXmlHttpRequstReplace("?Action="+Math.random(),document.all.pool);
}
//drop the scanning Thread
function DropThread(num){
if(confirm('Are U sure?')){
var url="?Action=del&id="+num+"&"+Math.random();
openUrlXmlHttpRequstEval(url,"");
}
}
function ThreadOperate(ope,id){
if(confirm('Are U sure?')){
var url="?Action="+ope+"&id="+id+"&"+Math.random();
openUrlXmlHttpRequstEval(url,"");
}
}
setInterval("viewSchedulerPool()",3000);
</script>
</head>
<body text="#00ff00" vLink="#008000" aLink="#008000" link="#008000" bgColor="#000000">
<center>
Scheduler Pool:
<div id="pool"></div>
<hr />
<form method="POST" name='S'>
HOST:<input type="text" name="host" />
START PORT:<input type="text" name="port" size="4" maxlength="5" />
END PORT:<input type="text" name="endPort" size="4" maxlength="5" />
THREAD:<select name="thread"><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option></select>
<input type="button" value="AddToScan" name="Action" οnclick="post();" />
</form>
</center>
<v:Textbox id=istuFullname style='FONT-SIZE:30;Z-INDEX:3201;FILTER:alpha(opacity=100,style=2) blur(add=0,direction=14,strength=5) wave(add=1,freq=,lightstrength=5,phase=5,strength=2) glow(color=#d9f281,strength=3) ;LEFT:10%;COLOR:#f17a35;FONT-FAMILY:@黑体;TOP:35%' inset='5pt,5pt,5pt,5pt'> - = Information Security Technology Organization = - </v:Textbox>
<a οnclick="javascript:window.open('http://www.isto.cn');">
<v:Textbox id=istu style="FONT-SIZE:80;Z-INDEX:3177;FILTER:alpha(opacity=100,style=2) blur(add=0,direction=14,strength=5) wave(add=1,freq=,lightstrength=5,phase=5,strength=8) glow(color=#cbb749,strength=1) invert;LEFT:23%;COLOR:black;WORD-BREAK:break-all;FONT-FAMILY:Arial Black;TOP:45%" inset="5pt,5pt,5pt,5pt" print="false">-= I.S.T.O =-</v:Textbox>
</a>
</body>
</html>
---------------------