asp.net、c#實現網頁小偷程序
      在asp中實現小偷是使用xmlhttp對象,最近在學習.net時看到了webclient類,于是將過去用來做小偷的程序改了一下,使用asp.net、c#來實現,程序寫的比較簡單,目的是為了起到拋磚引玉的作者,希望能與各位一起探討,使之更加完善,下一步我將使之實現根據設置可以獲取網頁中指定的內容。以下是程序部分,包括在web頁中的asp.net的源程序和c#中的源程序。
asp.net (getwebcontent.aspx)
<%@ page language="c#" %>
<%@ import namespace="system.net" %>
<%@ import namespace="system.text" %>
<script runat=server>
   //***********************************************************
   //*              
   //*    使用asp.net實現網站小偷的程序     
   //*       written by 笑笑 2005-12-11       
   //*       網址:http://blog.hnce.net       
   //*       email:[email protected] qq:5364083    
   //*               
   //***********************************************************
void page_load(object sender , eventargs e) 
{
   string strurl="http://blog.hnce.net";    //欲獲取的網頁地址
   
   webclient mywebclient=new webclient();    //創建webclient實例mywebclient
   
   //獲取或設置用于對向 internet 資源的請求進行身份驗證的網絡憑據。
   mywebclient.credentials=credentialcache.defaultcredentials;
   
   //從資源下載數據并返回字節數組。(加@是因為網址中間有"/"符號)
   byte[] pagedata=mywebclient.downloaddata(strurl);
   
   //以下兩句每次只要使用一條即可,功能是一樣是用來轉換字符集,根據獲取網站頁面的字符編碼選擇
   //string result=encoding.default.getstring(pagedata);        
   //如果獲取網站頁面采用的是gb2312,則使用這句
   string result=encoding.utf8.getstring(pagedata); 
   //如果獲取網站頁面采用的是utf-8,則使用這句 
   //因為我的博客使用了utf-8編碼,所以在這里我使用這句
   response.write(result);   //在web頁中顯示獲取的內容
}
</script>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<title>無標題文檔</title>
</head>
<body>
</body>
</html>
c# (getwebcontent.cs)
/*
*********************************************************
*       
*  使用c#實現網站小偷的程序   
*       written by 笑笑 2005-12-11   
*       網址:http://blog.hnce.net   
*       email:[email protected] qq:5364083 
*       
*********************************************************
*/
using system;
using system.net;
using system.text;
class getwebcontent
{
 public static void main()
 {           
     try
     {
webclient mywebclient = new webclient();
mywebclient.credentials = credentialcache.defaultcredentials;
  byte[] pagedata = mywebclient.downloaddata("http://blog.hnce.net");
  string pagehtml = encoding.utf8.getstring(pagedata);
  console.writeline(pagehtml);
     } 
     catch (webexception webex)
     {
  console.write(webex.tostring());
     }
 }
}
 asp.net、c#網頁小偷源程序打包下載 
新聞熱點
疑難解答
圖片精選