by nmcshane
18. November 2011 20:58
I'm sure you have all came across the problem of automatic spamming of forms using a robot.
One solution to this is to validate the email address on the form by checking that it is a valid domain name and chacking to see if the Mail Server exists.
- The code below extracts the domain name from the email address entered
- Carrys out a name server lookup
- If found you know that the email address is from a valid domain.
Dim address As String = "yourname@yourdomain.com"
Dim host As String() = (address.Split("@"c))
Dim hostname As String = host(1)
Dim info As New ProcessStartInfo()
Dim ns As Process
Dim sout As StreamReader
Dim mailserver As String = ""
Dim response As String = ""
info.UseShellExecute = False
info.RedirectStandardInput = True
info.RedirectStandardOutput = True
info.FileName = "nslookup"
info.Arguments = "-type=MX " + sDomain.ToUpper.Trim
ns = Process.Start(info)
sout = ns.StandardOutput
Dim reg As Regex = New Regex("mail exchanger = (?<server>[^\\\s]+)")
Do While (sout.Peek() > -1)
response = sout.ReadLine()
Dim amatch As Match = reg.Match(response)
If (amatch.Success) Then
mailserver = amatch.Groups("server").Value
Exit Do
End If
Loop
Return mailserver
20acf682-c2ac-4501-918e-f30900c1613f|0|.0
Tags: