Guest User

Untitled

a guest
Jul 12th, 2021
42
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import varint, socket, sys, time, json
  2. from binascii import unhexlify as uh, hexlify as he
  3.  
  4. host, port = "<Server address>", 25565
  5. uname = "<minecraft username>"
  6.  
  7. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  8. try:
  9.     s.connect((host, port))
  10. except ConnectionRefusedError:
  11.     print(f"{host}:{port} is OFFLINE")
  12.     sys.exit(1)
  13. msg = b""
  14. msg += b"\x00"                          #Packet ID: Handshake
  15. msg += varint.encode(755)               #Protocol version: 775(Minecraft version 1.17)
  16. msg += varint.encode(len(host))         #Hostname length prefix
  17. msg += host.encode()                    #Hostname
  18. msg += uh(hex(port).replace("0x", ""))  #Port
  19. msg += varint.encode(2)                 #Next state: 2=Login
  20. msg = varint.encode(len(msg))+msg       #Packet Length Prefix
  21. print(f"Handshake:\t{he(msg).decode()}")
  22. s.send(msg)
  23. time.sleep(2)
  24. msg = b"\x00"
  25. msg += hex(len(uname)).replace("0x", "").encode()   #Username length prefix
  26. msg += uname.encode()                               #Username
  27. msg = varint.encode(len(msg))+msg       #Packet Length Prefix
  28. s.send(msg)
  29. print(f"Login start:\t{he(msg).decode()}")
  30. msg = s.recv(1000)
  31. print(msg)
RAW Paste Data