Skip to content

Instantly share code, notes, and snippets.

@gdude2002
Created February 19, 2010 19:43
Show Gist options
  • Save gdude2002/309116 to your computer and use it in GitHub Desktop.
Save gdude2002/309116 to your computer and use it in GitHub Desktop.
import sys
import os
import datetime
import struct
import urllib
import urllib2
import re
import socket
import cookielib
import threading
class bot (threading.Thread):
def __init__(self, sock=None):
threading.Thread.__init__(self)
self.username = "gdudebot"
self.passw = "gdudeismyname"
if sock is None:
self.sock = socket.socket(socket.AF_INET, socket.SOCK_RAW)
else:
self.sock = sock
def run(self):
self.rip(sys.argv[1], self.username, self.passw)
def rip(self, key, username, password):
login_url = 'http://minecraft.net/login.jsp'
play_url = 'http://minecraft.net/play.jsp?server=%s'
cj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
login_data = urllib.urlencode({'username': username, 'password': password})
print "Logging in..."
opener.open(login_url, login_data)
print "Fetching server info..."
html = opener.open(play_url % key).read()
ip = re.search(r'param name\="server" value="([0-9.]+)"', html).groups()[0]
port = int(re.search(r'param name\="port" value="([0-9]+)"', html).groups()[0])
mppass = re.search(r'param name\="mppass" value="([0-9a-zA-Z]+)"', html).groups()[0]
print "Details:"
print ip
print port
print mppass
self.login(ip, port, mppass)
def login(self, ip, port, mppass):
self.username = "gdudebot"
packet = "\x00\x07"+self.pack(self.username, "STRING")+self.pack(mppass, "STRING")+"\x00"
print len(packet)
self.sock.connect((ip, port))
self.sock.send(packet)
# botrecv(self.sock).start()
def pack(self, string, type):
if type == "BYTE":
return string
elif type == "SHORT" and (len(string) < 2):
string = string + "\x20"*(2-len(string))
return string
elif type == "SHORT" and not (len(string) < 2):
return string
elif type == "STRING":
string = string + "\x20"*(64-len(string))
return string
elif type == "ARRAY":
return "We're never, ever handling arrays!"
class botrecv(threading.Thread):
def __init__(self, sock):
threading.Thread.__init__(self)
self.sock = sock
while True:
print self.sock.recv(64)
packet = "\x0d \x00 Test has worked!"
packed = packet + "\x00"*(64-len(packet))
self.sock.send(packed)
bot().start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment