看了一下。 套圈目前不是那么简单。 不过先打个酱油是没错的。
package main
import (
"fmt"
"crypto/md5"
"os"
"net/url"
)
const (
AuthenticatedString = "ad7502703678e3486c8814c260f51b7f"
)
func main(){
if len(os.Args) <= 1 {
fmt.Println("not enough parameters")
os.Exit(1)
}
urlInput, e:= url.Parse(os.Args[1])
if e!=nil {
fmt.Printf("%v\n", e)
os.Exit(1)
}
fmt.Printf("<%v>\n", urlInput.User) // *URL.Userinfo
if urlInput.User != nil {
fmt.Printf("username: %v\n", urlInput.User.Username())
if passwd, e:= urlInput.User.Password(); e{
fmt.Printf("password: %v\n", passwd)
} else {
fmt.Println("no password given")
}
}
auth := fmt.Sprintf("%v", urlInput.User)
hash := md5.New()
hash.Write([]byte(auth))
cipher:= hash.Sum(nil)
cipherStr := fmt.Sprintf("%x", cipher)
if AuthenticatedString == cipherStr {
fmt.Println("authenticated")
} else {
fmt.Println("unauthorized")
}
}