Suffering from Spam?

Suffering from Spam?

One of the major ways that spammers get email addresses is by crawling Web pages and extracting any email addresses they find. As part of your own Web site development, it’s a good idea to check your own Web pages to make sure you didn’t accidentally include any email addresses. Here’s a little VB.NET utility that can scan a Web page and extract most email addresses.

Private Sub cmdScan_Click(ByVal sender As System.Object, _   ByVal e As System.EventArgs) Handles cmdScan.Click   ScanAPage(txtURL.Text)End Sub

The Regex Regular Expression class does the scanning. This particular pattern breaks down as follows:

w+ One or more characters, numbers or underscores@ The @ symbolw+ One or more characters, numbers or underscores( A group consisting of.. A period followed byw+ One or more characters, numbers or underscores) End of the groupPrivate m_EmailRE As New Regex("w+@(w+)(.w+)+")

Now, this expression is not perfect?it will detect some invalid email addresses, but keep in mind what it is designed for. This application isn’t a tool for spammers to extract email addresses?it’s a tool to help you spot email addresses you’ve inadvertently left in your code. So false positives aren’t harmful. The AddToList function checks for duplicates before listing the email addresses:

Private Sub AddToList(ByVal s As String)   If Not ListBox1.Items.Contains(s.ToLower) Then      ListBox1.Items.Add(s.ToLower)   End IfEnd Sub

The ScanAPage function does the real work. It uses the WebRequest object to retrieve the specified Web page, then applies the Regular Expression to extract all patterns that match the email address, and adds them to the list:

Private Sub ScanAPage(ByVal url As String)   Dim req As WebRequest   req = WebRequest.Create(url)   Dim pageinfo As String   Dim response As WebResponse   Dim thisuri As New Uri(url)   Try      response = req.GetResponse()   Catch ex As Exception      Exit Sub   End Try   Dim sr As New IO.StreamReader(response.GetResponseStream)   pageinfo = sr.ReadToEnd()   response.Close()   Dim reresults As MatchCollection   Dim onematch As Match   ' Get Email addresses and add to list   reresults = m_EmailRE.Matches(pageinfo)   If Not reresults Is Nothing Then      For Each onematch In reresults         AddToList(onematch.Value)      Next   End IfEnd Sub

Dan Appleman is the president of Desaware, Inc. and the author of a number of programming books.

Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of