Last active
December 20, 2015 01:09
-
-
Save zyxar/6047346 to your computer and use it in GitHub Desktop.
日月光华原地满血复活脚本
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'); | |
var list = fs.readFileSync('login.lst').toString(); | |
list = list.replace(/\n/g, ' '); | |
var cookies = {}; | |
var http = require('http'); | |
var qs = require('querystring'); | |
var events = require('events'); | |
var emitter = new events.EventEmitter(); | |
var Login, Logout; | |
emitter.on('logon', function(arg, callback) { | |
// console.log(arg, "logon"); | |
callback(arg); | |
}); | |
Login = function (Id) { | |
if (Id === '' || Id === undefined || Id === null) { return; } | |
var payload = qs.stringify({id: Id, pw: '$YOUR PASSWORD$'}); | |
var connin = { | |
host: 'bbs.fudan.edu.cn', | |
port: 80, | |
path: '/bbs/login', | |
method: 'POST', | |
headers: { | |
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", | |
"Accept-Language": "zh-CN,zh;q=0.8", | |
"Cache-Control": "max-age=0", | |
"Connection": "keep-alive", | |
"Content-Length": payload.length, | |
"Content-Type": "application/x-www-form-urlencoded", | |
"DNT": 1, | |
"Host": "bbs.fudan.edu.cn", | |
"Origin": "http://bbs.fudan.edu.cn", | |
"Referer": "http://bbs.fudan.edu.cn/bbs/sec", | |
"User-Agent": "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.72 Safari/537.36" | |
} | |
}; | |
var req = http.request(connin, function (res) { | |
console.log(res.statusCode, res.headers["set-cookie"]); | |
cookies[Id] = res.headers["set-cookie"]; | |
emitter.emit('logon', Id, Logout); | |
}); | |
req.write(payload); | |
req.end(); | |
}; | |
Logout = function (Id) { | |
if (Id === '' || Id === undefined || Id === null) { return; } | |
var connoff = { | |
host: 'bbs.fudan.edu.cn', | |
port: 80, | |
path: '/bbs/logout', | |
method: 'GET', | |
headers: { | |
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", | |
"Accept-Language": "zh-CN,zh;q=0.8", | |
"Connection": "keep-alive", | |
"DNT": 1, | |
"Cookie": cookies[Id].join('; '), | |
"Host": "bbs.fudan.edu.cn", | |
"Referer": "http://bbs.fudan.edu.cn/bbs/sec", | |
"User-Agent": "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.72 Safari/537.36" | |
} | |
}; | |
var req = http.request(connoff, function (res) { | |
console.log(connoff.headers.Cookie, res.statusCode); | |
// console.log(res.headers); | |
}); | |
req.end(); | |
}; | |
list.split(' ').forEach(Login); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
比我以前基于 expect 写的 telnet 脚本方便多了!代码量也少!