Author Topic: [Go] IsEmail  (Read 898 times)

0 Members and 1 Guest are viewing this topic.

Offline kenjoe41

  • Symphorophiliac Programmer
  • Administrator
  • Baron
  • *
  • Posts: 990
  • Cookies: 224
    • View Profile
[Go] IsEmail
« on: September 04, 2014, 03:58:17 pm »
Well i have been learning golang(Go) in this silence while in my intern. I intend to make EZ love Go.
Here we go
Code: (sh) [Select]
$isemail kenjoe41@evilzone.orgtada;;
Code: (go) [Select]
package main

import (
"fmt"
"log"
"net"
"os"
"regexp"
"strings"
)

func main() {
if len(os.Args) != 2 {
fmt.Fprintf(os.Stderr, "Usage: isemail Email-Address : \nE.g. $isemail kenjoe41@mailinator.com\n")
os.Exit(1)
}

email := os.Args[1]

re := regexp.MustCompile("^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$") //regex for email structure;
if re.MatchString(email) {
fmt.Print("Email-Address structure is valid...\n")
} else {
log.Fatal("[-]Wrong Email-Address structure!\n")

}

//split email into uname and host
email_parts := strings.Split(email, "@") //returns an array
host := email_parts[1]
if _, err := net.LookupHost(host); err != nil {
fmt.Printf("[-]But DNS lookup failed for host: %s \n", host)
log.Fatal(err)
} else {
fmt.Print("[+]And Dns lookup was successful!\n")
}
fmt.Print("[\u263A]Email Address %v is valid.\n", email)//smile
}[/code
If you can't explain it to a 6 year old, you don't understand it yourself.
http://upload.alpha.evilzone.org/index.php?page=img&img=GwkGGneGR7Pl222zVGmNTjerkhkYNGtBuiYXkpyNv4ScOAWQu0-Y8[<NgGw/hsq]>EvbQrOrousk[/img]