使用VB实现邮箱自动注册(二):修改代理服务器
如果一个IP在一段时间过多的注册,则该IP会被封调,一个办法就是修改注册表以修改代理服务器。在这里我使用一个API函数internetsetoption,使用之前要添加一个模块,然后加入如下代码:
Public Const internet_option_proxy = 38
Public Const INTERNET_OPEN_TYPE_PROXY = 3
Public Const INTERNET_OPTION_SETTINGS_CHANGED = 39
Type INTERNET_PROXY_INFO
dwAccessType As Long
lpszProxy As String
lpszProxyBypass As String
End TypePublic Declare Function internetsetoption Lib "wininet.dll" _
Alias "InternetSetOptionA" _
(ByVal hinternet As Long, _
ByVal dwoption As Long, _
ByRef lpbuffer As Any, _
ByVal dwbufferlength As Long) As Long
改代码定义了三个常数和一个结构,该API函数的具体用法请大家查询MSDN。VB修改注册表的办法就太多了,我就不多说了。在WebBrowser1_DocumentComplete事件中在添加一个条件语句,用以判断是否是IP被封的提示页面,代码如下:
If InStr(doc.body.innerText, "IP地址在这一段时间内已经注册了太多的用户") > 0 Then
Dim options As INTERNET_PROXY_INFO
options.dwAccessType = INTERNET_OPEN_TYPE_PROXY
options.lpszProxy = "168.10.46.77:80"
options.lpszProxyBypass = ""
internetsetoption 0, internet_option_proxy, options, LenB(options)
Dim don As Double
Dim doff As Double
Set reg = CreateObject("Wscript.Shell")
a = reg.regwrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyServer", _
"211.144.96.250:80")
a = reg.regwrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable", _
1)
internetsetoption 0, INTERNET_OPTION_SETTINGS_CHANGED, 0, 0
WebBrowser1.Navigate "http://freemail.eyou.com/signup.html?bgp=%CE%D2%BD%D3%CA%DC&bgp_enable=on"
End If
至此代理服务器的修改也完成了。
对于一些有验证码的网站如何识别出图片上的验证码,我还没有办法解决,我试着用VC写了一个图片识别程序,但效果很不理想,希望大家多交流。
如果一个IP在一段时间过多的注册,则该IP会被封调,一个办法就是修改注册表以修改代理服务器。在这里我使用一个API函数internetsetoption,使用之前要添加一个模块,然后加入如下代码:
Public Const internet_option_proxy = 38
Public Const INTERNET_OPEN_TYPE_PROXY = 3
Public Const INTERNET_OPTION_SETTINGS_CHANGED = 39
Type INTERNET_PROXY_INFO
dwAccessType As Long
lpszProxy As String
lpszProxyBypass As String
End TypePublic Declare Function internetsetoption Lib "wininet.dll" _
Alias "InternetSetOptionA" _
(ByVal hinternet As Long, _
ByVal dwoption As Long, _
ByRef lpbuffer As Any, _
ByVal dwbufferlength As Long) As Long
改代码定义了三个常数和一个结构,该API函数的具体用法请大家查询MSDN。VB修改注册表的办法就太多了,我就不多说了。在WebBrowser1_DocumentComplete事件中在添加一个条件语句,用以判断是否是IP被封的提示页面,代码如下:
If InStr(doc.body.innerText, "IP地址在这一段时间内已经注册了太多的用户") > 0 Then
Dim options As INTERNET_PROXY_INFO
options.dwAccessType = INTERNET_OPEN_TYPE_PROXY
options.lpszProxy = "168.10.46.77:80"
options.lpszProxyBypass = ""
internetsetoption 0, internet_option_proxy, options, LenB(options)
Dim don As Double
Dim doff As Double
Set reg = CreateObject("Wscript.Shell")
a = reg.regwrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyServer", _
"211.144.96.250:80")
a = reg.regwrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable", _
1)
internetsetoption 0, INTERNET_OPTION_SETTINGS_CHANGED, 0, 0
WebBrowser1.Navigate "http://freemail.eyou.com/signup.html?bgp=%CE%D2%BD%D3%CA%DC&bgp_enable=on"
End If
至此代理服务器的修改也完成了。
对于一些有验证码的网站如何识别出图片上的验证码,我还没有办法解决,我试着用VC写了一个图片识别程序,但效果很不理想,希望大家多交流。
代码不是很规范,将就着看吧,呵呵
Private Declare Function GetObject Lib "GDI32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
Private Declare Function GetBitmapBits Lib "GDI32" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long
Private Type BITMAP
bmType As Long
bmWidth As Long
bmHeight As Long
bmWidthBytes As Long
bmPlanes As Integer
bmBitsPixel As Integer
bmBits As Long
End Type
Function PICTURE(Url As String, Int1 As Long) As String
On Error Resume Next
Dim Bilden() As Byte
Dim Filestr As String
Dim Fileint As Integer
Fileint = Int(Rnd * 10)
Filestr = CStr(Fileint)
If Int1 <> 5 Then
Picture1.Enabled = True
Bilden() = Inet1.OpenURL(Url, icByteArray)
Open App.Path + "\" + Filestr + ".bmp" For Binary Access Write As #1 ' Save the file.
Put #1, , Bilden()
Close #1
Inet1.Cancel
Picture1.Picture = LoadPicture(App.Path + "\" + Filestr + ".bmp")
End If
Dim hBitmap As Long
Dim res As Long
Dim bmp As BITMAP
Dim byteAry() As Byte
Dim Totbyte As Long, i As Long
hBitmap = Picture1.Picture.Handle
res = GetObject(hBitmap, Len(bmp), bmp) '取得BitMap的结构 Totbyte = bmp.bmWidthBytes * bmp.bmHeight '总共要多少个Byte来存图 ReDim byteAry(Totbyte - 1)
'Debug.Print Totbyte
'将该图全放进ByteAry中
res = GetBitmapBits(hBitmap, Totbyte, byteAry(0))
Dim ff As Long, gg As Long, jj As Long
Dim Newary(1080) As Byte
gg = 0
If Int1 = 5 Then
For jj = 1 To Totbyte - 2 Step 4
If byteAry(jj) < 40 Then
byteAry(jj) = 0
End If
Newary(gg) = byteAry(jj)
gg = gg + 1
Next
End If
If Int1 = 0 Then
For jj = 1 To Totbyte - 2 Step 3
If byteAry(jj) < 40 Then
byteAry(jj) = 0
End If
Newary(gg) = byteAry(jj)
gg = gg + 1
Next
End If
If Int1 = 1 Then
For jj = 1 To Totbyte - 2 Step 3
If byteAry(jj) > 126 And byteAry(jj) < 130 Then
byteAry(jj) = 0
End If
Newary(gg) = byteAry(jj)
gg = gg + 1
Next
End If
Picture1.Enabled = False
MYPICTURE = Dispchar(Newary())
End Function
Function Dispchar(Ary1() As Byte) As String
Dim i As Integer, j As Integer, k As Integer
Dim str1 As String
On Error Resume Next
'MsgBox Ary1(1000)
str1 = ""
For i = 0 To 59
For j = 0 To 17
If Ary1(i + 60 * j) = 0 And j > 2 Then
If Ary1(i + 60 * j + 60) > 0 And Ary1(i + 60 * j + 120) > 0 And Ary1(i + 60 * j + 180) > 0 And Ary1(i + 60 * j + 240) > 0 And Ary1(i + 60 * j + 300) = 0 Then
str1 = str1 + "1"
i = i + 6
Exit For
End If
If j > 11 And Ary1(i + 60 * j + 60) = 0 And Ary1(i + 60 * j - 59) > 0 Then
str1 = str1 + "5"
i = i + 6
Exit For
End If
If j > 6 And Ary1(i + 60 * j + 60) = 0 And Ary1(i + 60 * j + 120) > 0 And Ary1(i + 60 * j + 180) > 0 And Ary1(i + 60 * j + 240) = 0 And Ary1(i + 60 * j + 300) = 0 And Ary1(i + 60 * j + 360) > 0 Then
str1 = str1 + "2"
i = i + 6
Exit For
End If
If j > 9 And Ary1(i + 60 * j + 60) = 0 And Ary1(i + 60 * j + 62) = 0 And Ary1(i + 60 * j + 120) > 0 Then
str1 = str1 + "4"
i = i + 6
Exit For
End If
If Ary1(i + 60 * j + 60) = 0 And Ary1(i + 60 * j + 120) = 0 And Ary1(i + 60 * j + 180) = 0 And Ary1(i + 60 * j + 240) > 0 And Ary1(i + 60 * j + 300) > 0 And Ary1(i + 60 * j + 360) > 0 And Ary1(i + 60 * j + 420) > 0 And Ary1(i + 60 * j + 480) > 0 And Ary1(i + 60 * j + 242) = 0 Then
str1 = str1 + "9"
i = i + 6
Exit For
End If
If j > 5 And Ary1(i + 60 * j + 60) = 0 And Ary1(i + 60 * j + 120) > 0 And Ary1(i + 60 * j + 180) > 0 And Ary1(i + 60 * j + 240) > 0 And Ary1(i + 60 * j + 300) = 0 And Ary1(i + 60 * j + 360) = 0 And Ary1(i + 60 * j + 420) > 0 Then
str1 = str1 + "3"
i = i + 6
Exit For
End If
If j < 5 And Ary1(i + 60 * j + 60) = 0 And Ary1(i + 60 * j + 120) = 0 And Ary1(i + 60 * j + 180) > 0 And Ary1(i + 60 * j + 240) = 0 And Ary1(i + 60 * j + 300) = 0 And Ary1(i + 60 * j + 360) = 0 And Ary1(i + 60 * j + 420) = 0 Then
str1 = str1 + "8"
i = i + 6
Exit For
End If
If Ary1(i + 60 * j + 60) = 0 And Ary1(i + 60 * j + 120) = 0 And Ary1(i + 60 * j + 1) = 0 And Ary1(i + 60 * j + 2) = 0 And Ary1(i + 60 * j + 3) = 0 And Ary1(i + 60 * j + 4) = 0 And Ary1(i + 60 * j + 5) = 0 And Ary1(i + 60 * j + 180) > 0 Then
str1 = str1 + "7"
i = i + 6
Exit For
End If
If Ary1(i + 60 * j + 60) = 0 And Ary1(i + 60 * j + 120) = 0 And Ary1(i + 60 * j + 180) = 0 And Ary1(i + 60 * j + 240) = 0 And Ary1(i + 60 * j + 300) = 0 And Ary1(i + 60 * j + 360) > 0 Then
str1 = str1 + "6"
i = i + 6
Exit For
End If
If Ary1(i + 60 * j + 60) = 0 And Ary1(i + 60 * j + 120) = 0 And Ary1(i + 60 * j + 180) = 0 And Ary1(i + 60 * j + 240) = 0 And Ary1(i + 60 * j + 300) > 0 And Ary1(i + 60 * j + 360) > 0 And Ary1(i + 60 * j + 420) > 0 Then
str1 = str1 + "0"
i = i + 6
Exit For
End If
End If
Next
Next
Dispchar = str1End Function
(过程是这样的,先用INET取得图片BYTE(是JPEG或GIF等),直接存为BMP,然后读入图片框中进行分解,分解后根据各位进行判断~~)