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

首頁 > 學院 > 開發設計 > 正文

兩個獲取http頁面的c#函數

2019-11-18 19:50:21
字體:
來源:轉載
供稿:網友

埋頭苦干一天終于搞定!一個用C#寫的windows應用程序,作用嘛,就是對asp程序已知的20種漏洞進行掃描,顯示源程序。在這個應用程序中用到兩種獲得http頁面的方法,一種是直接用httpwebrequest類,而另一種是同服務器通過tcp/ip建立socket連接,直接查詢端口80 , 為此我寫了以下兩個函數,第一個比較簡單,參數只有一個,就是要求的url , 另外一個比較復雜,也很通用,不僅可以請求http頁面,還可以和其他端口通信,如端口43的whois,端口25的smtp,端口21的ftp甚至pop3等等,三個參數分別是主機名,請求命令和端口。好了,看程序吧。

//獲取http頁面函數
PRivate string Get_Http(string a_strUrl)
{
string strResult ;
HttpWebRequest myReq = (HttpWebRequest)
WebRequestFactory.Create(a_strUrl) ;

try
{
HttpWebResponse HttpWResp = (HttpWebResponse)myReq.GetResponse();
Stream myStream = HttpWResp.GetResponseStream () ;

StreamReader sr = new StreamReader(myStream , Encoding.Default);
StringBuilder strBuilder = new StringBuilder();
while (-1 != sr.Peek())
{
strBuilder.Append(sr.ReadLine()+"/r/n");
}

strResult = strBuilder.ToString();
}
catch(Exception exp)
{
strResult = "錯誤:" + exp.Message ;
}

return strResult ;

}


//通過同server建立tcp/ip連接,發送socket命令
private string Get_Socket_Request(string a_strServer , string a_strRequest , Int32 a_intPort)
{
//Set up variables and String to write to the server
Encoding ASCII = Encoding.Default ;
string Get = a_strRequest + "Connection: Close/r/n/r/n";
//string Get =
Byte[] ByteGet = ASCII.GetBytes(Get);
Byte[] RecvBytes = new Byte[256];
String strRetPage = null;

// IPAddress and IPEndPoint represent the endpoint that will
// receive the request
IPAddress hostadd = DNS.Resolve(a_strServer.Substring(7 ,a_strServer.Length - 7));
IPEndPoint EPhost = new IPEndPoint(hostadd, a_intPort);

//Create the Socket for sending data over TCP
Socket s = new Socket(AddressFamily.AfINet, SocketType.SockStream,
ProtocolType.ProtTCP );

// Connect to host using IPEndPoint
if (s.Connect(EPhost) != 0)
{
strRetPage = "Unable to connect to host";
return strRetPage;
}

// Sent the GET text to the host
s.Send(ByteGet, ByteGet.Length, 0);

// Receive the page, loop until all bytes are received
Int32 bytes = s.Receive(RecvBytes, RecvBytes.Length, 0);
strRetPage = strRetPage + ASCII.GetString(RecvBytes, 0, bytes);

while (bytes > 0)
{
bytes = s.Receive(RecvBytes, RecvBytes.Length, 0);
strRetPage = strRetPage + ASCII.GetString(RecvBytes, 0, bytes);
}

return strRetPage ;
}

 

 

 


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 扬州市| 满城县| 正安县| 武隆县| 苗栗市| 芮城县| 阿坝县| 东光县| 玛多县| 南汇区| 西华县| 邻水| 沅陵县| 察哈| 同仁县| 天全县| 长兴县| 呼和浩特市| 门头沟区| 霍林郭勒市| 阿克苏市| 汝阳县| 绍兴县| 丹巴县| 大同县| 屯昌县| 息烽县| 五大连池市| 满城县| 酒泉市| 阜平县| 洛川县| 紫阳县| 阜康市| 体育| 牟定县| 宁安市| 宁陕县| 榆社县| 龙游县| 图们市|