using Mysticals Wrapper to set up a login? *UPDATE!

Discussion in 'Code Snippets and Tutorials' started by Heya_old, Nov 5, 2008.

  1. Heya_old

    Heya_old Level IV

    Joined:
    Mar 31, 2008
    Messages:
    928
    Likes Received:
    46
    can someone explain better ho thats done. I'm a bit confused on it. i've been rading up on guides on VB.NET, and iknow how POST and GET variables work, but i can't seem to figure out y the rest :( help will get you +rep :) i'm also kind of cconfused on how you control another class to come up after the login, or is the login spose to be a popup? thanks if you help:) sorry if i sound noobish.
     
  2. tharoux

    tharoux Level IV

    Joined:
    Dec 30, 2006
    Messages:
    2,733
    Likes Received:
    126
    Location:
    In front of my PC, Montreal
    Re: using Mysticals Wrapper to set up a login?

    I was about to get back to you cause I was lacking a bit of time earlier ;)

    here's the wrapper I'm using... it's mystical one. I know I changed some lines for my needs but I can't remember witch one.
    There's also a getbetween function in there. :) It's a class so don't put it IN you form class.

    Code (Text):
    1. Public Class TCPWrapper
    2.     Inherits System.Windows.Forms.UserControl
    3. #Region " Windows Form Designer generated code "
    4.     Public Sub New()
    5.         MyBase.New()
    6.         'This call is required by the Windows Form Designer.
    7.         InitializeComponent()
    8.         'Add any initialization after the InitializeComponent() call
    9.     End Sub
    10.     'UserControl overrides dispose to clean up the component list.
    11.     Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
    12.         If disposing Then
    13.             If Not (components Is Nothing) Then
    14.                 components.Dispose()
    15.             End If
    16.         End If
    17.         MyBase.Dispose(disposing)
    18.     End Sub
    19.     'Required by the Windows Form Designer
    20.     Private components As System.ComponentModel.IContainer
    21.     'NOTE: The following procedure is required by the Windows Form Designer
    22.     'It can be modified using the Windows Form Designer.
    23.     'Do not modify it using the code editor.
    24.     <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    25.         components = New System.ComponentModel.Container
    26.     End Sub
    27. #End Region
    28.     Private colCookies As New Collection
    29.     Dim strCookies As String
    30.     Public LastPage As String
    31.     Public Function Request(ByVal Method As String, ByVal URL As String, ByVal Referer As String) As String
    32.         Dim Host As String = Nothing
    33.         Dim strFile As String = Nothing
    34.         Dim strPost As String = Nothing
    35.         Dim pos As Integer = 0
    36.         If Referer Is Nothing Then
    37.             Referer = LastPage
    38.         End If
    39.         If URL.Contains("http://") Then
    40.             Host = URL.Substring(7)
    41.         Else
    42.             Host = URL
    43.         End If
    44.         If Host.Contains("/") Then
    45.             pos = Host.IndexOf("/", 0)
    46.             strFile = Host.Substring(pos)
    47.             Host = Host.Substring(0, pos)
    48.         Else
    49.             strFile = "/"
    50.         End If
    51.         If Method = "POST" Then
    52.             pos = strFile.IndexOf("?")
    53.             If Not (pos = -1) Then
    54.                 strPost = strFile.Substring(pos + 1)
    55.                 strFile = strFile.Substring(0, pos)
    56.             Else
    57.                 strPost = Nothing
    58.             End If
    59.         End If
    60.         If Method = "POST2" Then
    61.             pos = strFile.IndexOf("?")
    62.             If Not (pos = -1) Then
    63.                 strPost = strFile.Substring(pos + 1)
    64.                 strFile = strFile.Substring(0, pos)
    65.             Else
    66.                 strPost = ""
    67.             End If
    68.         End If
    69.         LastPage = URL
    70.         Dim ReqHeaders As String = Nothing
    71.         If Method = "GET" OrElse Method = "PIC" Then
    72.             ReqHeaders = "GET" + " " + strFile + " HTTP/1.1" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Host: " + Host + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.8.0.7) Gecko/20060909 Firefox/1.5.0.7" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Accept-Language: en-us,en;q=0.5" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Accept-Encoding: gzip, deflate" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Keep-Alive: 300" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Connection: keep-alive" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Referer: " + Referer + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Cookie: " + strCookies + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & ""
    73.         Else
    74.             ReqHeaders = "POST " + strFile + " HTTP/1.1" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Host: " + Host + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.8.0.7) Gecko/20060909 Firefox/1.5.0.7" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Accept-Language: en-us,en;q=0.5" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Accept-Encoding: gzip, deflate" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Keep-Alive: 300" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Connection: keep-alive" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Referer: " + Referer + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Cookie: " + strCookies + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Content-Type: application/x-www-form-urlencoded" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Content-Length: " + strPost.Length.ToString + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Connection: close" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + strPost
    75.         End If
    76.         If Method = "PIC" Then
    77.             ReqHeaders.Replace("Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5", "Accept: image/png,*/*;q=0.5")
    78.         End If
    79.  
    80.         Dim tcp As New System.Net.Sockets.TcpClient
    81.         Dim netstream As System.Net.Sockets.NetworkStream
    82.         Dim TN(1) As Long
    83.         If Referer = "" Then Referer = LastPage
    84.         If InStr(1, URL, "http://") <> 0 Then Host = Mid$(URL, 8)
    85.         If InStr(1, Host, "/") <> 0 Then Host = Mid$(Host, 1, InStr(1, Host, "/") - 1)
    86.         If InStr(1, Host, "?") <> 0 Then Host = Mid$(Host, 1, InStr(1, Host, "?") - 1)
    87.         LastPage = URL
    88.         Try
    89.             tcp.Connect(Host, 80)
    90.         Catch ex As Exception
    91.             Return ex.Message
    92.         End Try
    93.  
    94.         Dim sendbytes As Byte()
    95.         sendbytes = System.Text.Encoding.ASCII.GetBytes(ReqHeaders)
    96.         netstream = tcp.GetStream()
    97.         netstream.Write(sendbytes, 0, sendbytes.Length)
    98.         Dim sr As StreamReader = New StreamReader(netstream, Encoding.Default)
    99.         Dim strHTML As String = sr.ReadToEnd
    100.         Dim strParts As String() = Regex.Split(strHTML, Environment.NewLine + Environment.NewLine)
    101.         strCookies = ParseCookies(strParts(0))
    102.         If strParts(0).Contains("Content-Encoding") Then
    103.             strParts(1) = DecompressGzip(strParts(1))
    104.         End If
    105.  
    106.         Return strParts(0) + Environment.NewLine + Environment.NewLine + strParts(1)
    107.     End Function
    108.     Public Function DecompressGzip(ByVal compressed As String) As String
    109.         Dim memStream As MemoryStream = New MemoryStream(System.Text.Encoding.Default.GetBytes(compressed))
    110.         Dim decompressStream As GZipStream = New GZipStream(memStream, CompressionMode.Decompress)
    111.         Dim endBytes(4) As Byte
    112.         Dim position As Integer = CType(memStream.Length, Integer) - 4
    113.         memStream.Position = position
    114.         memStream.Read(endBytes, 0, 4)
    115.         memStream.Position = 0
    116.         Dim buffer(BitConverter.ToInt32(endBytes, 0) + 100) As Byte
    117.         Dim offset As Integer = 0
    118.         Dim total As Integer = 0
    119.         While True
    120.             Dim bytesRead As Integer = decompressStream.Read(buffer, offset, 100)
    121.             If bytesRead = 0 Then
    122.                 Exit While
    123.             End If
    124.             offset += bytesRead
    125.             total += bytesRead
    126.         End While
    127.         Return Encoding.ASCII.GetString(buffer)
    128.     End Function
    129.     Public Function ParseCookies(ByVal Headers As String) As String
    130.         ParseCookies = ""
    131.         Dim reg As Regex
    132.         Dim matches As MatchCollection
    133.         Dim match As Match
    134.         reg = New Regex("set-cookie:\s*([^=]+)=([^;]+);", RegexOptions.IgnoreCase)
    135.         If reg.IsMatch(Headers) Then
    136.             matches = reg.Matches(Headers)
    137.             For Each match In matches
    138.                 Try
    139.                     colCookies.Add(match.Groups(1).ToString & "=" & match.Groups(2).ToString, match.Groups(1).ToString)
    140.                 Catch ex As Exception
    141.                     colCookies.Remove(match.Groups(1).ToString)
    142.                     colCookies.Add(match.Groups(1).ToString & "=" & match.Groups(2).ToString, match.Groups(1).ToString)
    143.                 End Try
    144.             Next
    145.         End If
    146.         Dim i As Long
    147.         For i = 1 To colCookies.Count Step 1
    148.             ParseCookies = ParseCookies & colCookies.Item(i).ToString & ";"
    149.         Next
    150.     End Function
    151.     Public Function StripHeaders(ByVal strSource As String) As String
    152.         Dim strParts() As String = Regex.Split(strSource, Environment.NewLine + Environment.NewLine)
    153.         Return strParts(1)
    154.     End Function
    155.     Public Function NeoLogin(ByVal user As String, ByVal pass As String, ByRef loggedIn As Boolean) As String
    156.         Dim strHTML As String = Nothing
    157.         Request("GET", "http://www.neopets.com/loginpage.phtml", "http://www.google.com")
    158.         Pause(1)
    159.         Request("POST", "http://www.neopets.com/hi.phtml?destination=%2Findex.phtml&username=" + user, "http://www.neopets.com/loginpage.phtml")
    160.         Pause(1)
    161.         strHTML = Request("POST", "http://www.neopets.com/login.phtml?username=" + user + "&password=" + pass + "&destination=%2Findex.phtml", "http://www.neopets.com/hi.phtml")
    162.         If strHTML.Contains("Set-Cookie: neologin=") Then
    163.             loggedIn = True
    164.             Return "Logged In"
    165.         Else
    166.             If strHTML.Contains("too many times") Then
    167.                 loggedIn = False
    168.                 Return "To Many Login Attempts"
    169.             Else
    170.                 If strHTML.Contains("badpassword") Then
    171.                     loggedIn = False
    172.                     Return "Wrong Username/Password"
    173.                 Else
    174.                     If strHTML.Contains("frozen") Then
    175.                         loggedIn = False
    176.                         Return "Account Frozen"
    177.                     Else
    178.                         If strHTML.Contains("just a technical problem") Then
    179.                             loggedIn = False
    180.                             Return "Neopets is down for maintenance"
    181.                         Else
    182.                             loggedIn = False
    183.                             Return "Unknow Error"
    184.                         End If
    185.                     End If
    186.                 End If
    187.             End If
    188.         End If
    189.     End Function
    190.     Private Shared Sub Pause(ByVal seconds As Double)
    191.         Dim num As Double = seconds * 1000
    192.         Dim t1 As DateTime = DateTime.Now
    193.         Dim t2 As DateTime = DateTime.Now
    194.         Dim tmDiff As TimeSpan = t2 - t1
    195.         While Convert.ToDouble(tmDiff.TotalMilliseconds.ToString) < num
    196.             t2 = DateTime.Now
    197.             tmDiff = t2 - t1
    198.             Application.DoEvents()
    199.         End While
    200.     End Sub
    201.     Public Function GrabPic(ByVal strURL As String) As System.Drawing.Image
    202.         Dim memStream As New MemoryStream(System.Text.Encoding.Default.GetBytes(StripHeaders(Request("GET", strURL, LastPage))))
    203.         GrabPic = Image.FromStream(memStream)
    204.         Return GrabPic
    205.     End Function
    206.     Public Sub ClearCookies()
    207.         colCookies.Clear()
    208.         strCookies = Nothing
    209.     End Sub
    210.     Public Function GetBetween(ByVal Source As String, ByVal Start As String, ByVal Finish As String) As String
    211.         Dim Result = ""
    212.         Dim A = InStr(1, Source, Start) + Len(Start)
    213.         If A = 0 Then
    214.             Result = ""
    215.             Return Result
    216.         Else
    217.             Dim B = InStr(A, Source, Finish)
    218.             If B = 0 Then
    219.                 Result = ""
    220.                 Return Result
    221.             Else
    222.                 Result = Mid(Source, A, B - A)
    223.                 Return Result
    224.             End If
    225.         End If
    226.     End Function
    227. End Class
    You'll also need to declare this at the very beginning (before your form class)
    Code (Text):
    1. Imports System.Text.Regularexpressions
    2. Imports System.Net
    3. Imports System.IO
    4. Imports System.Text
    5. Imports System.IO.Compression
    6. Imports System.Runtime.Serialization.Formatters.Binary

    Finally, you need to declare a new Wrapper variable:
    Code (Text):
    1. Private Wrapper As New TCPWrapper
    The login function (already incorporated in the wrapper class)
    Code (Text):
    1. Dim Response = Wrapper.NeoLogin(txtUser.Text, txtPass.Text, False)
    If everything is fine, you'll receive "Logged In". If there was a problem during login, the "response" variable will contain the reason.
    Code (Text):
    1. If Response = "Logged In" Then
    Now, to use those "get" and "post" function. There's two ways of using the get. With a referer or without. If you don't specify one, the program wrapper class will take care of it.
    Code (Text):
    1. Wrapper.Request("GET", "http://www.neopets.com/quickref.phtml", "")
    2. Wrapper.Request("GET", "http://www.neopets.com/pound/", "http://www.neopets.com/quickref.phtml")
    And finally, the post command.
    Code (Text):
    1. Wrapper.Request("POST", "http://www.neopets.com/pound/process_adopt.phtml?pet_name=" + txtPetName.Text, "http://www.neopets.com/pound/adopt.phtml?search=" + txtPetName.Text)
    2.  
    In all those cases, if you do a "get" or "post" and want to analyze the information returned, you need to put them in a variable.
    Code (Text):
    1. Response = Wrapper.request(blahblahblahblah)
    Now, +rep me a thousand times :p
     
  3. Heya_old

    Heya_old Level IV

    Joined:
    Mar 31, 2008
    Messages:
    928
    Likes Received:
    46
    Re: using Mysticals Wrapper to set up a login?

    um... now getting the authorization sysrem getting worked in is causing problems... i've been playing with it all day, but idk what i'm doing wrong. heres the file:
     
  4. tharoux

    tharoux Level IV

    Joined:
    Dec 30, 2006
    Messages:
    2,733
    Likes Received:
    126
    Location:
    In front of my PC, Montreal
    Re: using Mysticals Wrapper to set up a login?

    oops, it will never work... I changed something in the wrapper for my needs and it screw up the login part...
    take this wrapper instead ;) (same thing but unmodified)

    Code (Text):
    1. Public Class TCPWrapperAuth
    2.     Inherits System.Windows.Forms.UserControl
    3. #Region " Windows Form Designer generated code "
    4.     Public Sub New()
    5.         MyBase.New()
    6.         'This call is required by the Windows Form Designer.
    7.         InitializeComponent()
    8.         'Add any initialization after the InitializeComponent() call
    9.     End Sub
    10.     'UserControl overrides dispose to clean up the component list.
    11.     Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
    12.         If disposing Then
    13.             If Not (components Is Nothing) Then
    14.                 components.Dispose()
    15.             End If
    16.         End If
    17.         MyBase.Dispose(disposing)
    18.     End Sub
    19.     'Required by the Windows Form Designer
    20.     Private components As System.ComponentModel.IContainer
    21.     'NOTE: The following procedure is required by the Windows Form Designer
    22.     'It can be modified using the Windows Form Designer.
    23.     'Do not modify it using the code editor.
    24.     <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    25.         components = New System.ComponentModel.Container
    26.     End Sub
    27. #End Region
    28.     Private colCookies As New Collection
    29.     Dim strCookies As String
    30.     Public LastPage As String
    31.     Public bGzip As Boolean
    32.     Public Function Request(ByVal Method As String, ByVal URL As String, ByVal Referer As String) As String
    33.         Dim Host As String = Nothing
    34.         Dim strFile As String = Nothing
    35.         Dim strPost As String = Nothing
    36.         Dim pos As Integer = 0
    37.         If Referer Is Nothing Then
    38.             Referer = LastPage
    39.         End If
    40.         If URL.Contains("http://") Then
    41.             Host = URL.Substring(7)
    42.         Else
    43.             Host = URL
    44.         End If
    45.         If Host.Contains("/") Then
    46.             pos = Host.IndexOf("/", 0)
    47.             strFile = Host.Substring(pos)
    48.             Host = Host.Substring(0, pos)
    49.         Else
    50.             strFile = "/"
    51.         End If
    52.         If Method = "POST" Then
    53.             pos = strFile.IndexOf("?")
    54.             If Not (pos = -1) Then
    55.                 strPost = strFile.Substring(pos + 1)
    56.                 strFile = strFile.Substring(0, pos)
    57.             Else
    58.                 strPost = Nothing
    59.             End If
    60.         End If
    61.         LastPage = URL
    62.         Dim ReqHeaders As String = Nothing
    63.         If bGzip = True Then
    64.             If Method = "GET" OrElse Method = "PIC" Then
    65.                 ReqHeaders = "GET" + " " + strFile + " HTTP/1.1" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Host: " + Host + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.8.0.7) Gecko/20060909 Firefox/1.5.0.7" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Accept-Language: en-us,en;q=0.5" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Accept-Encoding: gzip, deflate" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Keep-Alive: 300" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Connection: keep-alive" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Referer: " + Referer + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Cookie: " + strCookies + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & ""
    66.             Else
    67.                 ReqHeaders = "POST " + strFile + " HTTP/1.1" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Host: " + Host + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.8.0.7) Gecko/20060909 Firefox/1.5.0.7" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Accept-Language: en-us,en;q=0.5" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Accept-Encoding: gzip, deflate" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Keep-Alive: 300" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Connection: keep-alive" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Referer: " + Referer + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Cookie: " + strCookies + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Content-Type: application/x-www-form-urlencoded" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Content-Length: " + strPost.Length.ToString + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Connection: close" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + strPost
    68.             End If
    69.             If Method = "PIC" Then
    70.                 ReqHeaders.Replace("Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5", "Accept: image/png,*/*;q=0.5")
    71.             End If
    72.         Else
    73.             If Method = "GET" OrElse Method = "PIC" Then
    74.                 ReqHeaders = "GET" + " " + strFile + " HTTP/1.1" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Host: " + Host + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.8.0.7) Gecko/20060909 Firefox/1.5.0.7" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Accept-Language: en-us,en;q=0.5" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" & "" + "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Keep-Alive: 300" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Connection: keep-alive" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Referer: " + Referer + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Cookie: " + strCookies + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & ""
    75.             Else
    76.                 ReqHeaders = "POST " + strFile + " HTTP/1.1" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Host: " + Host + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.8.0.7) Gecko/20060909 Firefox/1.5.0.7" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Accept-Language: en-us,en;q=0.5" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Keep-Alive: 300" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Connection: keep-alive" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Referer: " + Referer + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Cookie: " + strCookies + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Content-Type: application/x-www-form-urlencoded" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Content-Length: " + strPost.Length.ToString + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "Connection: close" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "" + strPost
    77.             End If
    78.             If Method = "PIC" Then
    79.                 ReqHeaders.Replace("Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5", "Accept: image/png,*/*;q=0.5")
    80.             End If
    81.         End If
    82.  
    83.         Dim tcp As New System.Net.Sockets.TcpClient
    84.         Dim netstream As System.Net.Sockets.NetworkStream
    85.         Dim TN(1) As Long
    86.         If Referer = "" Then Referer = LastPage
    87.         If InStr(1, URL, "http://") <> 0 Then Host = Mid$(URL, 8)
    88.         If InStr(1, Host, "/") <> 0 Then Host = Mid$(Host, 1, InStr(1, Host, "/") - 1)
    89.         If InStr(1, Host, "?") <> 0 Then Host = Mid$(Host, 1, InStr(1, Host, "?") - 1)
    90.         If Mid$(Host, 1, 4) = "www." Then Host = Mid$(Host, 5)
    91.         LastPage = URL
    92.         Try
    93.             tcp.Connect(Host, 80)
    94.         Catch ex As Exception
    95.             Return ex.Message
    96.         End Try
    97.  
    98.         Dim sendbytes As Byte()
    99.         sendbytes = System.Text.Encoding.ASCII.GetBytes(ReqHeaders)
    100.         netstream = tcp.GetStream()
    101.         netstream.Write(sendbytes, 0, sendbytes.Length)
    102.         Dim sr As StreamReader = New StreamReader(netstream, Encoding.Default)
    103.         Dim strHTML As String = sr.ReadToEnd
    104.         Dim strParts As String() = Regex.Split(strHTML, Environment.NewLine + Environment.NewLine)
    105.         strCookies = ParseCookies(strParts(0))
    106.         If strParts(0).Contains("Content-Encoding") Then
    107.             strParts(1) = DecompressGzip(strParts(1))
    108.         End If
    109.         Return strParts(1)
    110.     End Function
    111.     Public Function DecompressGzip(ByVal compressed As String) As String
    112.         Dim memStream As MemoryStream = New MemoryStream(System.Text.Encoding.Default.GetBytes(compressed))
    113.         Dim decompressStream As GZipStream = New GZipStream(memStream, CompressionMode.Decompress)
    114.         Dim endBytes(4) As Byte
    115.         Dim position As Integer = CType(memStream.Length, Integer) - 4
    116.         memStream.Position = position
    117.         memStream.Read(endBytes, 0, 4)
    118.         memStream.Position = 0
    119.         Dim buffer(BitConverter.ToInt32(endBytes, 0) + 100) As Byte
    120.         Dim offset As Integer = 0
    121.         Dim total As Integer = 0
    122.         While True
    123.             Dim bytesRead As Integer = decompressStream.Read(buffer, offset, 100)
    124.             If bytesRead = 0 Then
    125.                 Exit While
    126.             End If
    127.             offset += bytesRead
    128.             total += bytesRead
    129.         End While
    130.         Return Encoding.ASCII.GetString(buffer)
    131.     End Function
    132.     Public Function ParseCookies(ByVal Headers As String) As String
    133.         ParseCookies = ""
    134.         Dim reg As Regex
    135.         Dim matches As MatchCollection
    136.         Dim match As Match
    137.         reg = New Regex("set-cookie:\s*([^=]+)=([^;]+);", RegexOptions.IgnoreCase)
    138.         If reg.IsMatch(Headers) Then
    139.             matches = reg.Matches(Headers)
    140.             For Each match In matches
    141.                 Try
    142.                     colCookies.Add(match.Groups(1).ToString & "=" & match.Groups(2).ToString, match.Groups(1).ToString)
    143.                 Catch ex As Exception
    144.                     colCookies.Remove(match.Groups(1).ToString)
    145.                     colCookies.Add(match.Groups(1).ToString & "=" & match.Groups(2).ToString, match.Groups(1).ToString)
    146.                 End Try
    147.             Next
    148.         End If
    149.         Dim i As Long
    150.         For i = 1 To colCookies.Count Step 1
    151.             ParseCookies = ParseCookies & colCookies.Item(i).ToString & ";"
    152.         Next
    153.     End Function
    154.     Public Function StripHeaders(ByVal strSource As String) As String
    155.         Dim strParts() As String = Regex.Split(strSource, Environment.NewLine + Environment.NewLine)
    156.         Return strParts(1)
    157.     End Function
    158.     Private Shared Sub Pause(ByVal seconds As Double)
    159.         Dim num As Double = seconds * 1000
    160.         Dim t1 As DateTime = DateTime.Now
    161.         Dim t2 As DateTime = DateTime.Now
    162.         Dim tmDiff As TimeSpan = t2 - t1
    163.         While Convert.ToDouble(tmDiff.TotalMilliseconds.ToString) < num
    164.             t2 = DateTime.Now
    165.             tmDiff = t2 - t1
    166.             Application.DoEvents()
    167.         End While
    168.     End Sub
    169.     Public Function GrabPic(ByVal strURL As String) As System.Drawing.Image
    170.         Dim memStream As New MemoryStream(System.Text.Encoding.Default.GetBytes(StripHeaders(Request("GET", strURL, LastPage))))
    171.         GrabPic = Image.FromStream(memStream)
    172.         Return GrabPic
    173.     End Function
    174.     Public Function DownloadImage(ByVal URL As String) As System.Drawing.Image
    175.         Dim imageFile As New WebClient
    176.         Dim bytes() As Byte = imageFile.DownloadData(URL)
    177.  
    178.         Dim imageStream As New MemoryStream(bytes)
    179.         Dim downloadedImage As System.Drawing.Image = Image.FromStream(imageStream)
    180.  
    181.         DownloadImage = downloadedImage
    182.     End Function
    183.     Public Sub ClearCookies()
    184.         colCookies.Clear()
    185.         strCookies = Nothing
    186.     End Sub
    187. End Class
     
  5. Heya_old

    Heya_old Level IV

    Joined:
    Mar 31, 2008
    Messages:
    928
    Likes Received:
    46
    Error 1 'NeofriendsLogin' is not a member of 'WindowsApplication1.TCPWrapperAuth'. C:\Documents and Settings\Owner\My Documents\WindowsApplication1\WindowsApplication1\Form1.vb 51 24 WindowsApplication1
     
  6. tharoux

    tharoux Level IV

    Joined:
    Dec 30, 2006
    Messages:
    2,733
    Likes Received:
    126
    Location:
    In front of my PC, Montreal
    sure you're aint using the nf auth system for vb6 ;)
    And the auth system you can find on the forum here need some work to work.
     
  7. Heya_old

    Heya_old Level IV

    Joined:
    Mar 31, 2008
    Messages:
    928
    Likes Received:
    46
    i'm using the one that expon posted... i forgot to add it, and when i aded the NeoFriendsLogin function with the auth code expon posted in it, 6 errors came up :(

    Error 1 'lblStatus2' is not a member of 'WindowsApplication1.TCPWrapperAuth'.
    Error 2 Name 'txtNFUser' is not declared.
    Error 3 Name 'txtNFPass' is not declared.
    Error 4 'lblStatus2' is not a member of 'WindowsApplication1.TCPWrapperAuth'.
    Error 5 'lblStatus2' is not a member of 'WindowsApplication1.TCPWrapperAuth'.
    Error 6 'lblStatus2' is not a member of 'WindowsApplication1.TCPWrapperAuth'.
     
  8. tharoux

    tharoux Level IV

    Joined:
    Dec 30, 2006
    Messages:
    2,733
    Likes Received:
    126
    Location:
    In front of my PC, Montreal
    seriously, take your time... starting with vb.net and wanting to code a program using inet control seems to be way above what you can do for the moment. If you can't understand how to use an external class within your main one, you're screwed.
    Maybe you wanted a bit to much at the same time. The error in your last post are pretty basic one, so that lead me to the fact that it may very well be the first time you use vb. Start simple, using program without class, playing with the GUI, properties of each control, then start implementing class, simple one, to see how they work. Unfortunately, I don't have any website or book for this, for search around, there's plenty of them. I don't want to demotivate you, far from it. Just don't try to skip a step in the learning process. ;)

    edit: like I stated previously, the auth system posted by expon here won't work out of the box. Work need to be done on it.
     
  9. Infection

    Infection Newbie

    Joined:
    Nov 10, 2008
    Messages:
    4
    Likes Received:
    0
    Location:
    Daytona Beach, Florida
    why not just ask mystical to help you out with the wrapper or write your own.
     
  10. tharoux

    tharoux Level IV

    Joined:
    Dec 30, 2006
    Messages:
    2,733
    Likes Received:
    126
    Location:
    In front of my PC, Montreal
    maybe because mystical is not on this forum anymore ;)
     
  11. Infection

    Infection Newbie

    Joined:
    Nov 10, 2008
    Messages:
    4
    Likes Received:
    0
    Location:
    Daytona Beach, Florida
    oh well that makes sense then :)
     
  12. Dusk412

    Dusk412 Level I

    Joined:
    Aug 2, 2008
    Messages:
    88
    Likes Received:
    9
    When you posted your *fixed* version of Mysticals Wrapper, you forgot the NeoLogin function. Just add it back in between Pause and GrabPic. That fixes those errors you were getting.

    MODS: Sorry for the gravedig, but I was learning how to use wrappers and I was using this, and having it miss that slightly vital code screwed me and I spent over an hour searching. Saving others the trouble. Sorry again.

    Code (Text):
    1.     Public Function NeoLogin(ByVal user As String, ByVal pass As String, ByRef loggedIn As Boolean) As String
    2.         Dim strHTML As String = Nothing
    3.         Request("GET", "http://www.neopets.com/loginpage.phtml", "http://www.google.com")
    4.         Pause(1)
    5.         Request("POST", "http://www.neopets.com/hi.phtml?destination=%2Findex.phtml&username=" + user, "http://www.neopets.com/loginpage.phtml")
    6.         Pause(1)
    7.         strHTML = Request("POST", "http://www.neopets.com/login.phtml?username=" + user + "&password=" + pass + "&destination=%2Findex.phtml", "http://www.neopets.com/hi.phtml")
    8.         If strHTML.Contains("Set-Cookie: neologin=") Then
    9.             loggedIn = True
    10.             Return "Logged In"
    11.         Else
    12.             If strHTML.Contains("too many times") Then
    13.                 loggedIn = False
    14.                 Return "To Many Login Attempts"
    15.             Else
    16.                 If strHTML.Contains("badpassword") Then
    17.                     loggedIn = False
    18.                     Return "Wrong Username/Password"
    19.                 Else
    20.                     If strHTML.Contains("frozen") Then
    21.                         loggedIn = False
    22.                         Return "Account Frozen"
    23.                     Else
    24.                         If strHTML.Contains("just a technical problem") Then
    25.                             loggedIn = False
    26.                             Return "Neopets is down for maintenance"
    27.                         Else
    28.                             loggedIn = False
    29.                             Return "Unknow Error"
    30.                         End If
    31.                     End If
    32.                 End If
    33.             End If
    34.         End If
    35.     End Function
    Edit: Aww crap, even after all that, now I get an 'Unknown Error' from the login code. Does anyone have an updated wrapper?!
     
  13. tharoux

    tharoux Level IV

    Joined:
    Dec 30, 2006
    Messages:
    2,733
    Likes Received:
    126
    Location:
    In front of my PC, Montreal
    Here's the complete wrapper with a simple login form - fully functionnal.
    Just unzip the file and open the solution.
    Dunno what was your error but I know that all the information posted here is correct.
     
  14. Dusk412

    Dusk412 Level I

    Joined:
    Aug 2, 2008
    Messages:
    88
    Likes Received:
    9
    Thanks tharoux, I will look at it later, I was just briefly checking in.