go - Making a post request in golang -
i'm trying automate following using golang
generate password(done)push notification devices(done using pushbullet)- change wifi router password @ 192.168.0.1 (needs done)
wifi router page @ 192.168.0.1 wifi router page
here raw data captured using fiddler. (when manually changed)
post http://192.168.0.1/goform/form2wlanbasicsetup.cgi http/1.1 host: 192.168.0.1 user-agent: mozilla/5.0 (windows nt 6.3; wow64; rv:43.0) gecko/20100101 firefox/43.0 accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 accept-language: en-us,en;q=0.5 accept-encoding: gzip, deflate referer: http://192.168.0.1/d_wlan_basic.asp cookie: curshow= x-skyzip-mode: high connection: keep-alive content-type: application/x-www-form-urlencoded content-length: 233 domain=1&hiddenssid=0&ssid=home&band=9&chan=0&chanwid=1&txrate=0&method_cur=0&method=6&authtype=2&length=1&format=1&defaulttxkeyid=1&key1=&pskformat=0&pskvalue=3adi0nsxeayoi0m&checkwps2=1&save=apply&basicrates=496&operrates=4080 and golang code follows
func routerpass(pass string) { routerurl := "http://192.168.0.1" resource := "/goform/form2wlanbasicsetup.cgi" data := url.values{} data.set("domain", "1") data.add("ssid", "home") data.add("band", "9") data.add("chan", "0") data.add("chanwid", "1") data.add("txrate", "0") data.add("method_cur", "0") data.add("method", "6") data.add("authtype", "2") data.add("length", "1") data.add("format", "1") data.add("defaulttxkeyid", "1") data.add("pskformat", "0") data.add("pskvalue", pass) data.add("checkwps2", "1") data.add("save", "apply") data.add("basicrates", "496") data.add("operrates", "4080") u, _ := url.parserequesturi(routerurl) u.path = resource u.rawquery = data.encode() urlstr := fmt.sprintf("%v", u) client := &http.client{} r, _ := http.newrequest("post", urlstr, nil) // r.header.add("authorization", "auth_token=\"xxxxxxx\"") r.header.add("content-type", "application/x-www-form-urlencoded") r.header.add("content-length", strconv.itoa(len(data.encode()))) resp, _ := client.do(r) fmt.println(pass) fmt.println(resp.status) } but i'm not able change password. doing wrong?
hopefully, others.
code worked
func changepassword(password string) { hc := http.client{} routerurl := "http://192.168.0.1/goform/form2wlanbasicsetup.cgi" form := url.values{} form.add("domain", "1") form.add("hiddenssid", "0") form.add("ssid", "linux-pc") form.add("band", "9") form.add("chan", "0") form.add("chanwid", "1") form.add("txrate", "0") form.add("method_cur", "0") form.add("method", "6") form.add("authtype", "2") form.add("length", "1") form.add("format", "1") form.add("defaulttxkeyid", "1") form.add("key1", "") form.add("pskformat", "0") form.add("pskvalue", password) form.add("checkwps2", "1") form.add("save", "apply") form.add("basicrates", "496") form.add("operrates", "4080") req, err := http.newrequest("post", routerurl, strings.newreader(form.encode())) if err != nil { panic(err) } req.postform = form req.header.add("user-agent", "mozilla/5.0 (windows nt 6.3; wow64; rv:43.0) gecko/20100101 firefox/43.0") req.header.add("referer", "http://192.168.0.1/d_wlan_basic.asp") req.header.add("content-type", "application/x-www-form-urlencoded") fmt.println(form) resp, err := hc.do(req) if err != nil { panic(err) } fmt.println(resp.status) fmt.println(password) }
Comments
Post a Comment