I wrote the following script to pull broadband usage form digiweb.
Its fairly hilarious that digiweb are so badly organized.
They are still using smart telecom forums for customers to access pertinent data.
Furthermore the connection is http rather than https.
Here’s to passing un-encrypted passwords over the wire! 🙂
Digiweb figures are exactly 10% more that what DD-WRT reports. Interesting observation 😉
Enjoy 😉
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | package main import ( "fmt" "strconv" "net/http" "net/http/cookiejar" "crypto/tls" "io/ioutil" "crypto/md5" "encoding/hex" "net/url" "strings" "regexp" ) var _smart_username = "username" var _smart_password = "password" var _modem_username = "0123456789" var _modem_password = "password" var _forum_endpoint = "http://support.smarttelecom.ie/forums/login.php?do=login" var _usage_endpoint = "http://support.smarttelecom.ie/forums/smart_usage" func GetMD5Hash(text string) string { hasher := md5.New() hasher.Write([]byte(text)) return hex.EncodeToString(hasher.Sum(nil)) } func getusage() { tr := &http.Transport { TLSClientConfig: &tls.Config { InsecureSkipVerify: true }, } cookieJar, _ := cookiejar.New(nil) client1 := &http.Client { Transport: tr, Jar: cookieJar } form1 := url.Values{} form1.Add( "vb_login_username", _smart_username ) form1.Add( "vb_login_password", "" ) form1.Add( "s", "" ) form1.Add( "securitytoken", "guest" ) form1.Add( "do", "login" ) form1.Add( "vb_login_md5password", GetMD5Hash( _smart_password ) ) form1.Add( "vb_login_md5password_utf", GetMD5Hash( _smart_password ) ) //fmt.Printf("%s", GetMD5Hash(_smart_password)) req1, err := http.NewRequest( "POST", _forum_endpoint, strings.NewReader(form1.Encode()) ) req1.Header.Add( "Content-Type", "application/x-www-form-urlencoded" ) resp1, err := client1.Do( req1 ) defer resp1.Body.Close() if err != nil { fmt.Printf( "Error : %s", err) } if resp1.StatusCode != 200 { fmt.Printf( "Error code: %s", strconv.Itoa( resp1.StatusCode ) ) } client2 := &http.Client { Transport: tr, Jar: cookieJar } form2 := url.Values{} form2.Add( "user", _modem_username ) form2.Add( "pass", _modem_password ) form2.Add( "submit", "SUBMIT" ) req2, err := http.NewRequest( "POST", _usage_endpoint, strings.NewReader(form2.Encode()) ) req2.Header.Add( "Content-Type", "application/x-www-form-urlencoded" ) resp2, err := client2.Do( req2 ) defer resp2.Body.Close() if err != nil { fmt.Printf( "Error : %s", err) } if resp1.StatusCode != 200 { fmt.Printf( "Error code: %s", strconv.Itoa( resp1.StatusCode ) ) } bodyBytes2, err := ioutil.ReadAll( resp2.Body ) if err != nil { fmt.Printf( "Error : %s", err ) } //fmt.Printf( "%s\n", bodyBytes2 ) re := regexp.MustCompile( "(?s)<table width=800 border=\"0\" style=\"border-collapse:collapse;\" cellspacing=\"0\">(.*)</table>" ) matches := re.FindAllString( string(bodyBytes2), -1 ) for i := len( matches )-1; i >= 0; i-- { reinout := regexp.MustCompile( "(?s)<td>(.*?)</td>" ) inout := reinout.FindAllString( matches[i] , -1 ) //fmt.Printf( "%v\n", inout[0][4:len(inout[0])-5] ) //fmt.Printf( "%v\n", inout[1][4:len(inout[1])-5] ) //fmt.Printf( "%v\n", inout[2][4:len(inout[2])-5] ) //fmt.Printf( "%v\n", inout[3][4:len(inout[3])-5] ) //fmt.Printf( "%v\n", inout[4][4:len(inout[4])-5] ) //fmt.Printf( "%v\n", inout[5][4:len(inout[5])-5] ) //fmt.Printf( "%v\n", inout[6][4:len(inout[6])-5] ) //fmt.Printf( "%v\n", inout[7][4:len(inout[7])-5] ) //fmt.Printf( "%v\n", inout[8][4:len(inout[8])-5] ) //fmt.Printf( "%v\n", inout[9][4:len(inout[9])-5] ) //fmt.Printf( "%v\n", inout[10][4:len(inout[10])-5] ) i := strings.Index(inout[11], "(") + 1 fmt.Printf( "%v\n", inout[11][i:len(inout[11])-10] ) } } func main() { getusage() } |