This is a creation in Article, where the information may have evolved or changed. Recently began to learn the go language, feel very interesting, then from the HTTP start, wrote a Web hang program. For Go version r59-201108 the latest version, low version compiled pass.
webqq.go/* *go Language Discussion group: 102319854 *go Language Official website: www.golang.org * Author: Undead crawler * Home: http://www.gososo.org http://www.daohang361.com /news/index.html * Witness Track * Garbled solution * *, DOS execution chcp 65001//Modify code page for Utf-8, otherwise you cannot compile * 2, modify the DOS window font to Lucida Console, otherwise the characters displayed are garbled * http://bbs.golang-china.org/viewtopic.php?f=4&t=8&start=10#p93 * CHCP Command: * chcp 65001 is replaced by UTF-8 code page, Right-click on the command line title bar, select Properties, font, modify the font to True type "Lucida Console", then click OK to apply the property to the current window * CHCP 936 can be swapped back to the default GBK * CHCP 437 is US English * /package mainimport ("FMT" "OS" "http" "NET" "RegExp" "Crypto/md5" "Hash" "Strings" "Encoding/hex" "Io/ioutil" "bytes" " Bufio ") var mcookies = make (Map[string] *http. Cookies)//save Cookievar QQ stringvar pass stringvar ptwebqq String//cookie value login and back with var skey string//cookie value Login and back with Var ClientID string= "63690451"//Random take var vfwebqq string//second return parameter var Psessionid string//Second login return parameter var refer stringfunc mai N () {fmt. Println ("If you run this first time,please run ' chcp 65001 ' on then cmd, then set front ' Lucida Console ') fmt. Println ("and run" chcp936 to back default ' ") If Len (OS. Args)! = 3 {fmt. Println ("Usage:", OS.) Args[0], "365183440 Pass") in: = Bufio. Newreader (OS. Stdin) Line, _: = in. ReadString (' \ n ') qq=strings. Split (line, "") [0] pass=strings. Split (line, "") [1] pass=strings. Trimspace (pass)}else{QQ = OS. ARGS[1]; Pass =os. ARGS[2];} Fmt. Println ("QQ:" +qq+ "pass:" +pass) refer= "http://web2-b.qq.com/proxy.html" S:=geturl ("http://ptlogin2.qq.com:80/ Check?appid=1003903&uin= "+qq,refer); var r=string (S[0:len (s)]) fmt. Println (R) var checktype string= "" Re,_:=regexp. Compile ("([^//']*)") S2:=re. Findallstring (r,-1) checktype=s2[3]fmt. Println ("Checktype:" +checktype) var checkcode string= "" Checkimg:if strings. Index (Checktype, "!") ==0{fmt. PRINTLN ("not need Checkcode") Checkcode=checktype; }else{fmt. PRINTLN ("Need Checkcode") checkcode=getimg ("http://captcha.qq.com:80/getimage?aid=1003903&uin=" +qq+ "&vc_ Type= "+checktype,refer)}fmt. Println ("CheckCode: "+checkcode"///Next Start landing//1th landing loginurl: = "http://ptlogin2.qq.com:80/login?u=" +qq+ "&" + "p=" +getcrypass ( Pass, Checkcode) + "&verifycode=" +checkcode+ "&remember_uin=1&aid=1003903" + "&u1=http%3a%2f% 2fweb2.qq.com%2floginproxy.html%3fstrong%3dtrue "+" &h=1&ptredirect=0&ptlang=2052&from_ui=1& Pttype=1&dumy=&fp=loginerroralert "; Rb:=geturl (Loginurl,refer) var LoginS string=string (rb[:]) fmt. Println (LoginS) if strings. Index (LoginS, "success") >0{fmt. Println ("First Landing successful!")} else if strings. Index (LoginS, "wrong Captcha") >0{fmt. Println ("The code is wrong!" re-get the captcha picture ") Goto checkimg}else if strings. Index (LoginS, "wrong password") >0{fmt. PRINTLN ("Wrong password!") Os. Exit (0)}else{fmt. PRINTLN ("Unknown error!") Os. Exit (0)}ptwebqq=mcookies["PTWEBQQ"]. valueskey=mcookies["Skey"]. Valuefmt.println ("Skey:" +skey) fmt. Println ("PTWEBQQ:" +PTWEBQQ)//landing again, only this landing, just calculate the real landing QQ, this time, if you QQ has landed, will put your QQ kicked off the line, and this landing is counted on the online channelloginurl: = "http/ D.web2.qq.com:80/channel/login2 "; Content: = "{\" status\: \ "\", \ "ptwebqq\": \ "" +ptwebqq+ "\", \ "passwd_sig\": \ "\", \ "clientid\": \ "" +clientid+ "\"} "; content = UrlEncode (content);//urlencodecontent =" r= "+ Content;//post Data Res: = PostURL (channelloginurl,refer,[]byte (content));//postre_twice:=string (res[:])// The second return is a JSON format, as below, we want to get Psessionid vfwebqq value/*{"Retcode": 0, "result": {"UIn": 526868457, "CIP": 1987728778, "index": 1075 , "Port": 40831, "status": "Online", "VFWEBQQ": " 6c47630a8cd98902d38d919420ffb019141ba7febd6b8ce02b0b69d7b85e0ad2205c8f141a66f364 "," Psessionid ":" 8368046764001d636f6e6e7365727665725f77656271714031302e3133342e362e31333800006023000005ee026e0400e95f671f6d0000000a4058474 d6430776c35476d000000286c47630a8cd98902d38d919420ffb019141ba7febd6b8ce02b0b69d7b85e0ad2205c8f141a66f364 "," User _state ": 0," F ": 0}}*/FMT. Print (Re_twice) Re,_=regexp.compile ("(vfwebqq\": \ ") ([^\"]*) (\ ")") S2=re. Findstringsubmatch (Re_twice) vfwebqq=s2[2]; Re,_=regexp.compile ("(psessionid\": \ ") ([^\"]*) (\ ")") S2=re. Findstringsubmatch (Re_twice) psessionid=s2[2] FMT. Println ("Psessionid:" +psessionid) Fmt. Println ("VFWEBQQ:" +vfwebqq) If Len (VFWEBQQ) ==0| | Len (Psessionid) ==0{FMT. PRINTLN ("Login Failed"); Os. Exit (0)}//To this login successfully called the poll Message Function poll ()}func UrlEncode (Urlin string) string{return HTTP. UrlEscape (Urlin)}func poll () {var pollurl string= "http://d.web2.qq.com:80/channel/poll2?clientid=" +clientid+ "& Psessionid= "+psessionid for {fmt. Println ("Get the message ....... ...................)") Fmt. Println ("Loop Get Message ..... ..... ........................... Fmt. Println (String (s[:]))}}/* * Gets the CAPTCHA picture and returns the input verification code */func getimg (Urlin string, refer String) String{imgbyte:=geturl (urlin,r Efer) fmt. Print ("Write IMG begin and the IMG length is:") fmt. Println (Len (imgbyte)) ERR2: = Ioutil. WriteFile ("D:/aa.jpg", imgbyte,0) if err2! = nil {fmt. Println (ERR2) return ""} FMT. PRINTLN ("Please open the file: D:/aa.jpg and enter the verification Code return"); Fmt. PRINTLN ("Need Checkcode Open:d:/aa.jpp input Checkcode"); var line string _, Err: = FMT. SCANLN (&line) if err!=Nil{return ""}return line}/* * with a cookie gets the URL */func getUrl (Urlin string, refer String) ([]byte) {URL, err: = http. parseURL (Urlin) checkerror (ERR)//Build a TCP connection firsthost: = URL. Hostconn, err: = Net. Dial ("TCP", host) CheckError (ERR)//Then wrap an HTTP client connection around Itclientconn: = http. NEWCLIENTCONN (conn, nil) if Clientconn = = Nil {fmt. Println ("Can ' t Build connection") OS. Exit (1)}//define the additional HTTP header fieldsheader: = map[string][] string {"Accept": {"text/html,application/ xhtml+xml,application/xml;q=0.9,*/*,q=0.8 "}," Accept-language ": {" zh-cn,zh;q=0.5 "}," Accept-charset ": {" UTF-8, utf-8;q=0.7,*;q=0.7 "}," Connection ": {" Keep-alive "}," Referer ": {refer}," User-agent ": {" mozilla/5.0 (Windows NT 5.1; rv:5.0) gecko/20100101 firefox/5.0 "},}//and build the requestrequest: = http. Request{method: "GET", Url:url, Header:header}for _, Value: = Range Mcookies {request. Addcookie (value)}dump, _: = http. Dumprequest (&request, False) Fmt. Println (String (dump))//Send the REQuesterr = Clientconn.write (&request) checkerror (ERR)//And get the responseresponse, err: = Clientconn.read (& Request) CheckError (ERR) if response. Status! = "OK" {fmt. PRINTLN (response. Status) OS. Exit (2)}//set-cookiefor I:=0;i<len (response. Cookies ()); I++{mcookies[response. Cookies () [i]. Name]=response. Cookies () [I]}const nbuf = 1 var buf =make ([]byte,nbuf)//http://code.google.com/p/golang-china/wiki/go_tutorialreader : = Response. Bodyresult: =make ([]byte,0)//We have a byte to avoid the problem of data coverage, but with the whole block read a little bit slower, so write for {switch nr, _: = Reader. Read (buf[:]); True {case Nr < 0:goto A1 break case nr = = 0://EOF goto a1break; Case NR > 0:result=append (result,buf[0])}}a1:return Result[0:len (Result)];} /* * With a cookie post */func posturl (Urlin string, refer String,sendbytes []byte) ([]byte) {URL, err: = http. parseURL (Urlin) checkerror (ERR)//Build a TCP connection firsthost: = URL. Hostconn, err: = Net. Dial ("TCP", host) CheckError (ERR)//Then Wrap an HTTP client connection around Itclientconn: = http. NEWCLIENTCONN (conn, nil) if Clientconn = = Nil {fmt. Println ("Can ' t Build connection") OS. Exit (1)}//define the additional HTTP header fieldsheader: = map[string][] string {"Accept": {"text/html,application/ xhtml+xml,application/xml;q=0.9,*/*,q=0.8 "}," Accept-language ": {" zh-cn,zh;q=0.5 "}," Accept-charset ": {" UTF-8, utf-8;q=0.7,*;q=0.7 "}," Content-type ": {" application/x-www-form-urlencoded "}," Connection ": {" Keep-alive "}," Transfer-encoding ": {" chunked "}," Referer ": {refer}," User-agent ": {" mozilla/5.0 "(Windows NT 5.1; rv:5.0) gecko/20100101 firefox/5.0 "},}//and build the requestrequest: = http. Request{method: "POST", Url:url, Header:header}request. Contentlength= (Int64) (Len (sendbytes)) for _, Value: = Range Mcookies {request. Addcookie (value)}request. Body= &closingbuffer{bytes. Newbuffer (Sendbytes)}dump, _: = http. Dumprequest (&request, False) Fmt. Println (String (dump))//Send the Requesterr = Clientconn.write (&request) cheCkerror (ERR)//And get the responseresponse, err: = Clientconn.read (&request) checkerror (ERR) if response. Status! = "OK" {fmt. PRINTLN (response. Status)}//set-cookiefor I:=0;i<len (response. Cookies ()); I++{mcookies[response. Cookies () [i]. Name]=response. Cookies () [I]}const nbuf = 1 var buf =make ([]byte,nbuf)//http://code.google.com/p/golang-china/wiki/go_tutorialreader : = Response. Bodyresult: =make ([]byte,0)//We have a byte to avoid the problem of data coverage, but with the whole block read a little bit slower, so write for {switch nr, _: = Reader. Read (buf[:]); True {case NR < 0:goto A2 break case nr = = 0://EOF goto a2break; Case NR > 0:result=append (result,buf[0])}}a2:return Result[0:len (Result)];} Func checkerror (Err os. Error) {if err! = Nil {fmt. PRINTLN ("Fatal error", Err. String ())//os. Exit (1)}}/* *webqq encryption Method */func Getcrypass (pass String,code String) String{crypss_3:=getmd5_3 (pass) crypss_3=strings. ToUpper (Hex. Encodetostring ([]byte (CrypsS_3)) +strings. ToUpper (Code) R:=GETMD5 (Crypss_3) return strings. ToUpper (Hex. Encodetostring (R[0:len (R))))}func Getmd5 (original string) []byte {var h hash. Hash = MD5. New () H.write ([]byte (original))//fmt. Printf ("%x\n", H.sum ()) return H.sum ()} func Getmd5_3 (in string) String{cry: =getmd5 (in) var R string=string (Cry[0:len (CR Y)]) cry =getmd5 (R) r=string (Cry[0:len (Cry)]) cry =getmd5 (R) r=string (Cry[0:len (Cry)]) return R}//implement IO. Readcloser interface type Closingbuffer struct {*bytes. Buffer}func (CB *closingbuffer) Close () (Err OS. Error) {//we don ' t actually has to does anything here, since the buffer is//just some data in memory//and t He error is initialized to No-error return}