1using System;
2using System.Data;
3using System.Configuration;
4using System.Collections;
5using System.Web;
6using System.Web.Security;
7using System.Web.UI;
8using System.Web.UI.WebControls;
9using System.Web.UI.WebControls.WebParts;
10using System.Web.UI.HtmlControls;
11using System.Net;
12using System.Text;
13using System.Net.Sockets;
14using System.IO;
15
16public partial class bb : System.Web.UI.Page
17{
18 protected void Page_Load(object sender, EventArgs e)
19 {
20 IPHostEntry ipHostEntry = Dns.Resolve("esales.16288.com");
21 IPAddress address = ipHostEntry.AddressList[0];
22 IPEndPoint point = new IPEndPoint(address, 80);
23 Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
24 try
25 {
26 client.Connect(point);
27 string s = "GET / HTTP/1.0/n Accept: */* /nUser-Agent: Mozilla/4.0.(compatible; MSIE.6.0; Windows NT 5.1) /n HOST: esales.16288.com /n Connection:Keep-Alive/n/n";
28 //string s = "GET /homepage.aspx HTTP/1.0/n User-Ageng: Mozilla/4.0.(compatible; MSIE.6.0; Windows NT 5.1) /n HOST: esales.16288.com /n Connection:Keep-Alive/n/n";
29 byte[] msgs = Encoding.Default.GetBytes(s);
30 client.Send(msgs);
31 byte[] bytes = new byte[4096];
32
33 int count;
34 string str = "";
35 count = client.Receive(bytes);
36 while (count > 0)
37 {
38
39 str += Encoding.Default.GetString(bytes, 0, count);
40 count = client.Receive(bytes);
41 }
42
43 //str是返回的内容
44 StreamWriter objSW = File.CreateText(Server.MapPath("body.txt"));
45 objSW.WriteLine(str);
46 objSW.Close();
47
48 }
49 catch (Exception ex)
50 {
51
52 }
53 finally
54 {
55 client.Shutdown(SocketShutdown.Both);
56 client.Close();
57 }
58 }
59 protected void Button1_Click(object sender, EventArgs e)
60 {
61
62
63 }
64
65}
66
1Imports System
2Imports System.Data
3Imports System.Configuration
4Imports System.Collections
5Imports System.Web
6Imports System.Web.Security
7Imports System.Web.UI
8Imports System.Web.UI.WebControls
9Imports System.Web.UI.WebControls.WebParts
10Imports System.Web.UI.HtmlControls
11Imports System.Net
12Imports System.Text
13Imports System.Net.Sockets
14Imports System.IO
15
16Public Class Default2
17 Inherits System.Web.UI.Page
18
19 '{
20 Protected Sub Page_Load(ByVal s As Object, ByVal e As EventArgs)
21 '{
22
23 '}
24 End Sub
25
26 Protected Sub Button1_Click(ByVal s As Object, ByVal e As EventArgs)
27
28 '{
29 Dim i As Integer
30 For i = 0 To 1000
31 ' Response.Write(GetCanshu("1") + "<br><br>")
32 ' Response.Write(GetCanshu("2") + "<br>")
33 ' Response.End()
34
35 Dim ipHostEntry As IPHostEntry = Dns.Resolve("esales.16288.com")
36 Dim address As IPAddress = ipHostEntry.AddressList(0)
37 Dim point As IPEndPoint = New IPEndPoint(address, 80)
38 Dim r As Random
39 r = New Random
40 Dim RanNum As String = r.Next(10000, 888888)
41 Dim client As Socket = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
42 Dim s1 As String = "GET /Validator/valid" + GetCanshu("2") + ".aspx?0." + RanNum + " HTTP/1.0" + vbCrLf + "User-Agent: Mozilla/4.0.(compatible; MSIE.6.0; Windows NT 5.1) " + vbCrLf + "HOST: esales.16288.com" + vbCrLf + "Cookie:ASP.NET_SessionID=" + GetCanshu("1") + ";path=/;HttpOnly" + vbCrLf + vbCrLf
43 ' Response.Write(s1.Replace(Chr(13), "<br/>"))
44 Try
45 '{
46 client.Connect(point)
47 'Dim r As Random = New Random()
48 'Dim RanNum As String = r.Next(1123, 99999)
49 '//string s = "GET /bby/website/GetValidateCodeImage.aspx?Digits=4&Width=80&Height=20 HTTP/1.0/nHOST: 192.168.1.27 /nCookie:ASP.NET_SessionID="+TextBox1.Text.Trim()+"; path=/; HttpOnly/n/n";
50
51 Dim msgs As Byte() = Encoding.Default.GetBytes(s1)
52
53 client.Send(msgs)
54 Dim bytes(4096) As Byte
55
56 Dim count As Integer 'int ;
57
58 Dim str As String = ""
59 Dim stream As FileStream = New FileStream(Server.MapPath(New Random().Next(1, 99999).ToString + DateTime.Now.Ticks.ToString + " .gif"), FileMode.Create)
60
61 Dim writer As BinaryWriter = New BinaryWriter(stream)
62
63 count = client.Receive(bytes)
64 writer.Write(bytes, 224, count - 224)
65 While (count > 0)
66 ' {
67
68 ' //str += Encoding.UTF8.GetString(bytes, 0, count);
69
70
71 count = client.Receive(bytes)
72 writer.Write(bytes, 0, count)
73 '}
74 End While
75
76
77
78 writer.Close()
79 stream.Close()
80
81
82 '}
83 Catch ex As Exception
84
85 Response.Write(ex.Message)
86 Finally
87 ' {
88 client.Shutdown(SocketShutdown.Both)
89 client.Close()
90 End Try
91 Next
92 '{
93 ' //SendMessage(ex.Message.ToString() + "<EOF>");
94 '}
95
96 '}
97
98 '}
99 End Sub
100 Function GetCanshu(ByVal a As String) As String
101 Dim str As String
102 Dim objStream As StreamReader = File.OpenText(Server.MapPath("body.txt"))
103 str = objStream.ReadToEnd()
104 objStream.Close()
105 'Dim a As String = "1"
106 If (a = "1") Then
107 '{
108 Dim array As Array ' string[] array;
109 array = Split(str, "SessionId=")
110 Dim canshu1 As String = Mid(array(1), 1, 24)
111 GetCanshu = canshu1
112 ' Response.Write(canshu1)
113 '}
114 Exit Function
115 Else
116 ' {
117 Dim array1 As Array ' string[] array1;
118 array1 = Split(str, "Validator/valid")
119 Dim canshu2 As String = Mid(array1(1), 1, 7)
120 GetCanshu = canshu2
121 ' Response.Write(canshu2)
122 Exit Function
123 End If
124 End Function
125
126
127
128
129End Class
http://www.cnblogs.com/dotnetblog/archive/2006/11/10/556956.html