Author Topic: Serverpinger  (Read 764 times)

thob

  • Traveller
  • *
  • Posts: 23
    • View Profile
Serverpinger
« on: January 25, 2011, 11:10:15 am »
Ähm, yes..

here it is:

http://paste.frubar.net/13313

Code: [Select]
# 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
Thob Ciscon, Crafter and Merchant for crafted Weapons.
Proud member of The Woiperdinger and the Merchantile Order of Commerce!

LigH

  • Forum Legend
  • *
  • Posts: 7096
    • View Profile
Re: Serverpinger
« Reply #1 on: January 26, 2011, 02:33:15 am »
No more "Laanx"; it's "ZeroPing" this time. ;)

Gag Harmond
Knight and Ambassador
The Royal House of Purrty

Earowo

  • Veteran
  • *
  • Posts: 1463
    • View Profile
    • Guild Site
Re: Serverpinger
« Reply #2 on: January 27, 2011, 12:21:10 am »
Im confuzzled, are you reccomending a new server? or an edit or what...
either way.. we've already switched twice, why ad more >.>
Dohmo: Please clean up your language immediately.
Me: as i just said, what i said, fits in the guidlines of rated PG, i was just explaining to the G guy
Dohmo: Sorry I tried to e nice
Dohmo: and i'm telling you to clean it up. last warning
Dohmo: now just do it
Dohmo: No more warnings

Abuse?

LigH

  • Forum Legend
  • *
  • Posts: 7096
    • View Profile
Re: Serverpinger
« Reply #3 on: January 27, 2011, 02:25:53 am »
Just a little edit (it's just a comment, so it doesn't matter anyway):
Code: [Select]
   ip = '62.173.168.9' # laanx
to
Code: [Select]
   ip = '62.173.168.9' # zeroping
The name is planeshift.zeroping.it - BTW.

Gag Harmond
Knight and Ambassador
The Royal House of Purrty

thob

  • Traveller
  • *
  • Posts: 23
    • View Profile
Re: Serverpinger
« Reply #4 on: January 27, 2011, 03:33:12 am »
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.
Thob Ciscon, Crafter and Merchant for crafted Weapons.
Proud member of The Woiperdinger and the Merchantile Order of Commerce!

firiban

  • Traveller
  • *
  • Posts: 27
    • View Profile
Re: Serverpinger
« Reply #5 on: January 29, 2011, 02:17:11 pm »
*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/), which displays the server status on your desktop.


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.
« Last Edit: January 30, 2011, 07:46:01 am by firiban »
Code: [Select]
    if (brain)
    {
        delete brain;
    }
From PlaneShift's npcclient code.