PlaneShift
Development => PlaneShift Mods => Topic started by: thob on January 25, 2011, 05:10:15 pm
-
Ähm, yes..
here it is:
http://paste.frubar.net/13313
# serverpinger.py by Thob
# Usage: Just run it! (It's python 3)
# You may want to change the ip adress or if it runs once/continously.
# License: WTFPL (http://sam.zoy.org/wtfpl/)
import socket
import random
import time
GENERIC = b'\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x08\x00\x00'
QUESTION = GENERIC + b'\x01\x05\x00\x00\x00\x00\x00\x03'
class Connection:
def __init__(self, ip, port):
self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self.socket.bind(('', random.randint(1025, 8000)))
self.socket.settimeout(2)
(self.port, self.ip) = (port, ip)
def poke(self):
self.socket.sendto(QUESTION, (self.ip, self.port))
try:
(msg, (ip, port)) = self.socket.recvfrom(1400)
if len(msg) == 23 and msg[15] == 1: # Is ping packet?
if msg[-1] == 6: state = 'up'
elif msg[-1] == 8: state = 'full'
elif msg[-1] == 4: state = 'up but locked'
else: state = 'is coming back up'
else: state = 'unkown'
except socket.timeout: state = 'down'
return 'Server ({}) {}!'.format(self.ip, state)
def one_time(con):
print(con.poke())
def continously(con, sleep):
time_1 = 3000
time_2 = 0
while True:
time_1 = time.time()
if time_1 - time_2 > sleep:
print(con.poke())
time_2 = time.time()
else:
time.sleep(0.5)
def main():
ip = '62.173.168.9' # laanx
#ip = '70.167.49.20' # ezpcusa
con = Connection(ip, 7777)
one_time(con)
#continously(con, 5)
if __name__ == '__main__':
try: main()
except KeyboardInterrupt: pass
Have fun... or ask questions.
Thob
-
No more "Laanx"; it's "ZeroPing" this time. ;)
-
Im confuzzled, are you reccomending a new server? or an edit or what...
either way.. we've already switched twice, why ad more >.>
-
Just a little edit (it's just a comment, so it doesn't matter anyway):
ip = '62.173.168.9' # laanx
to
ip = '62.173.168.9' # zeroping
The name is planeshift.zeroping.it - BTW.
-
Im confuzzled, are you reccomending a new server? or an edit or what...
either way.. we've already switched twice, why ad more >.>
Laanx is easier to remember as the main server.
And for sure you can use 'planeshift.zeroping.it' if it resolves the right way.
Thob
PS: Sorry, I expected basic knowledge of python. Ask if you are unsure about certain things.
-
*Firiban cheers*
great thing thob!
For all those who dont want to type ./serverpinger.py all the time, you can have this script in a shiny and tiny screenlet (http://www.screenlets.org/ (http://www.screenlets.org/)), which displays the server status on your desktop.
(http://imagebin.us/images/da2b0565d01o771bppfg.png)
May look like this in the end
1 install Screenlets (linux users → package manager of your distro | windows and mac users → go crying)
2 activate the screenlet called "Output"
3 right-click on that screenlet → Properties → Options → Options
4 "Command to run": /whereever/you/put/the/serverpinger.py (make sure the file is executable)
5 Click Apply
6 "Update interval seconds": Something that does not DDOS the server, but still is way up to date (maybe 5 or 10)
7 Optionally change colors, position, size, scale, etc.
8 Close Properties window and enjoy the server status on your Desktop.