| 1 | public class checkurl |
| 2 | Inherits System.Web.UI.Page |
| 3 | protected WithEvents ResURL as System.Web.UI.WebControls.Literal |
| 4 | protected WithEvents ErrMSG as System.Web.UI.WebControls.Literal |
| 5 | protected WithEvents PageHash as System.Web.UI.WebControls.Literal |
| 6 | protected WithEvents PageTitle as System.Web.UI.WebControls.Literal |
| 7 | protected WithEvents MetaURL as System.Web.UI.WebControls.Literal |
| 8 | protected WithEvents ReqUrl as System.Web.UI.WebControls.Literal |
| 9 | protected WithEvents Alliance1 as DPM.Alliance |
| 10 | protected WithEvents Alliance2 as DPM.Alliance |
| 11 | protected WithEvents Textbox1 as System.Web.UI.WebControls.TextBox |
| 12 | |
| 13 | private Sub Page_Load(ByVal sender as System.object, ByVal e as System.EventArgs) Handles MyBase.Load |
| 14 | Dim req as System.Net.HttpWebRequest |
| 15 | Dim res as System.Net.HttpWebResponse |
| 16 | Dim r as System.IO.StreamReader |
| 17 | Dim ex as Exception 'error exeption holder |
| 18 | Dim pge as string 'page holder |
| 19 | |
| 20 | if Page.IsPostBack Then |
| 21 | ReqUrl.Text = Textbox1.Text |
| 22 | |
| 23 | 'set up error trapping |
| 24 | Try |
| 25 | 'display request url |
| 26 | req = req.Create(Textbox1.Text) |
| 27 | |
| 28 | 'set the user agent |
| 29 | 'some site might brush you off if it is not set |
| 30 | 'to stop bots and scrapers |
| 31 | req.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3705)" |
| 32 | |
| 33 | 'get page |
| 34 | res = req.GetResponse() |
| 35 | r = new System.IO.StreamReader(res.GetResponseStream()) |
| 36 | pge = r.ReadToEnd |
| 37 | r.Close() |
| 38 | res.Close() |
| 39 | |
| 40 | 'display respondent url |
| 41 | ResURL.Text = res.ResponseUri.AbsoluteUri |
| 42 | |
| 43 | 'extract and display meta refresh tag, if it exists |
| 44 | MetaURL.Text = System.Text.RegularExpressions.Regex.Match(pge, "URL=(?<href>[^""]+)""").Groups("href").Value() |
| 45 | |
| 46 | 'extract and display page title |
| 47 | PageTitle.Text = System.Text.RegularExpressions.Regex.Match(pge, "<title>(?<title>[^<]+)</title>", System.Text.RegularExpressions.RegexOptions.IgnoreCase).Groups("title").Value |
| 48 | |
| 49 | Dim SHhash as new System.Security.Cryptography.SHA1Managed() |
| 50 | |
| 51 | 'convert the page to a byte array |
| 52 | Dim pgeb as byte() = System.Text.Encoding.ASCII.GetBytes(pge) |
| 53 | |
| 54 | 'get the hash as a byte array |
| 55 | Dim hashvalue as byte() = SHhash.ComputeHash(pgeb) |
| 56 | |
| 57 | 'display the hash as a string |
| 58 | Dim b as byte |
| 59 | PageHash.Text = "" |
| 60 | for Each b in hashvalue |
| 61 | PageHash.Text += Right("0" + Hex$(b), 2) |
| 62 | Next |
| 63 | ErrMSG.Text = "" |
| 64 | catch ex |
| 65 | 'display any error message |
| 66 | ErrMSG.Text = ex.Message |
| 67 | ResURL.Text = "" |
| 68 | MetaURL.Text = "" |
| 69 | PageTitle.Text = "" |
| 70 | PageHash.Text = "" |
| 71 | End Try |
| 72 | End if |
| 73 | 'reset the textbox |
| 74 | Textbox1.Text = "http://" |
| 75 | End Sub |
| 76 | |
| 77 | private Sub InitializeComponent() |
| 78 | |
| 79 | End Sub |
| 80 | End class |