建一个YanzhenCard.aspx文件
成都创新互联公司是一家专业提供娄烦企业网站建设,专注与成都网站设计、网站建设、H5技术、小程序制作等业务。10年已为娄烦众多企业、政府机构等服务。创新互联专业网站建设公司优惠进行中。
保留%@ Page Language="VB" AutoEventWireup="false" CodeFile="YanzhenCard.aspx.vb" Inherits="YanzhenCard" %,其余删除
如下是代码:
Imports System.IO
Imports System.Drawing
Partial Class YanzhenCard
Inherits System.Web.UI.Page
Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
Dim VNum As String = GenerateRandom(4)
Session("VNum") = VNum
ValidateCode(VNum)
End If
End Sub
Private Sub ValidateCode(ByVal VNum As String)
Dim Gheight As Integer = CType((VNum.Length * 15), Integer)
Dim Img As Bitmap = New Bitmap(Gheight, 20) 'Bitmap是用于处理由像素数据定义的图像
Dim g As Graphics = Graphics.FromImage(Img) 'Graphics.FromImage 从指定的Image创建新的Graphics
g.DrawString(VNum, New Font("Arial", 12), New SolidBrush(Color.Red), 5, 0) 'g.DrawString()在指定位置并且用指定的Brush和Font对象绘制指定的文本字符串。
Dim ms As MemoryStream = New MemoryStream '创建其支持存储区为内存的流。
Img.Save(ms, System.Drawing.Imaging.ImageFormat.Png)
Response.ClearContent()
Response.ContentType = "image/PNG"
Response.BinaryWrite(ms.ToArray)
Response.Write(VNum)
g.Dispose()
Img.Dispose()
Response.End()
End Sub
Private Shared constant As Char() = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}
Public Shared Function GenerateRandom(ByVal Length As Integer) As String
Dim newRandom As System.Text.StringBuilder = New System.Text.StringBuilder(26)
Dim rd As Random = New Random
Dim i As Integer = 0
While i Length
newRandom.Append(constant(rd.Next(26)))
System.Math.Min(System.Threading.Interlocked.Increment(i), i - 1)
End While
Return newRandom.ToString
End Function
End Class
调用方法:asp:ImageButton ID="Yanzhengma_Card" runat="server" ImageUrl="YanzhenCard.aspx" Height="20px" Width="75px" BorderColor="#6699cc" BorderStyle="Solid" BorderWidth="1px" /
一般登陆网站时候首先要打开一个网页对吧?
那首先要 GET 一个网址。GetResponse后,得到的流就是这个页面的源码。
源码里肯定会包含这个验证码的提问段(可能是个图片的网址,也可能是个 5+5=? 之类的字符串之类的),可以分析一下这段代码出现的位置,让程序自动寻找。找到这个图片的网址,把这个图片 GET 下来,然后,就是orc识别或你人工识别咯。。。
Dim CtrlRange As Object
On Error Resume Next
Do
Err.Clear()
CtrlRange = Ie.Document.Body.DomElement.createControlRange()
CtrlRange.Add(Ie.Document.DomDocument.GetElementById("verifypic"))
CtrlRange.execCommand("Copy") '获取验证码
If Clipboard.ContainsData(DataFormats.Bitmap) Then
PictureBox1.Image = Clipboard.GetData(DataFormats.Bitmap) '在Picture1控件上显示
End If
If Err.Number 0 Then WaitingMS(100) ‘延时
Loop While Err.Number 0
以前找的 vbnet里也可以用