title: Is there a way to ping IP address of computer to show them online (or offline) in GUI whenever they are connected to my server?
body: <p>I have a working client and server chat application developed in python. I intend to make it more dynamic by showing the computers that connected or disconnected to the server in a separate GUI. What is the way to proceed ?</p>
  
  <p>it is a simple chat-app. User/client  registers -> logs in -> enters the IP of the server pc ->chat widow pops up -> start chatting to another user connected to the same server </p>
  
  <p>Tried import os and ping but it only pings the computer. I want the sever to auto-detect the computers as soon as they connect the server. Server is created using MySQL. Running on Windows requires pymysql. </p>
  
  <p>SERVER CODE:</p>
  
  <pre><code>from threading import Thread
  #import MySQLdb
  import struct
  import pickle
  import pymysql
  
  
  def accept_incoming_connections():
      """Sets up handling for incoming clients."""
      while True:
          global client
          client, client_address = SERVER.accept()
          print("%s:%s has connected." % client_address)
          addresses[client] = client_address
          Thread(target=choice).start()
  
  
  def choice():
          a = client.recv(BUFSIZ).decode("utf8")
          if a =='1':
                  Thread(target=reg_client, args=(client,)).start()
          else:
                  Thread(target=login, args=(client,)).start()
  
  
  def handle_client(client,name):  # Takes client socket as argument.
      """Handles a single client connection."""
      #name = client.recv(BUFSIZ).decode("utf8")
      welcome = 'Welcome %s! If you ever want to quit, type {quit} to exit.' % name
      client.send(bytes(welcome, "utf8"))
      msg = "%s has joined the chat!" % name
      broadcast(bytes(msg, "utf8"))
      clients[client] = name
  
      while True:
          msg = client.recv(BUFSIZ)
          if msg != bytes("{quit}", "utf8"):
              broadcast(msg, name+": ")
          else:
              client.send(bytes("{quit}", "utf8"))
              client.close()
              del clients[client]
              broadcast(bytes("%s has left the chat." % name, "utf8"))
              break
  
  
  def reg_client(client):
      while True:
          a = client.recv(BUFSIZ)
          break;
      data_arr = pickle.loads(a)
      print(data_arr)
      #print(mobileno)
      #print(password)
      name=data_arr[0]
      mobileno=data_arr[1]
      password=data_arr[2]
  
      db = pymysql.connect("localhost","root","root","ChatApp" )
      cursor = db.cursor()
      sql="insert into user(name,mobileno,password) values(%s,%s,%s)"
      values=(name,mobileno,password)
      cursor.execute(sql,values)
      db.commit()
      cursor.close()
      db.close()
      Thread(target=choice).start()
  
  def login(client):
      while True:
          a = client.recv(BUFSIZ)
          data_arr = pickle.loads(a)
          print(data_arr)
          break;
      mobileno=data_arr[0]
      password=data_arr[1]
      print (mobileno)
      print(password)
      db = pymysql.connect("localhost","root","root","ChatApp" )
  
      #sql='SELECT * FROM user1 WHERE mobileno = %s and password = %s',(mobileno,password)
      sql='SELECT * FROM user WHERE mobileno = %s and password = %s'
      values=(mobileno,password)
      cursor = db.cursor()
      cursor.execute(sql,values)
      data = cursor.fetchall()
  
      for row in data:
          global name
          name=row[0]
      print("Name=",name)
  
      if data != None:
          client.send(bytes('1', "utf8"))
          print("success")
          Thread(target=handle_client, args=(client,name)).start()
      else:
          client.send(bytes('0', "utf8"))
      cursor.close()
      db.close()
      Thread(target=choice).start()
  
  
  
  def broadcast(msg, prefix=""):  # prefix is for name identification.
      """Broadcasts a message to all the clients."""
  
      for sock in clients:
          sock.send(bytes(prefix, "utf8")+msg)
  
  
  clients = {}
  addresses = {}
  
  HOST = ''
  PORT = 33000
  BUFSIZ = 1024
  ADDR = (HOST, PORT)
  
  SERVER = socket(AF_INET, SOCK_STREAM)
  SERVER.bind(ADDR)
  
  if __name__ == "__main__":
      SERVER.listen(5)
      print("Waiting for connection...")
      ACCEPT_THREAD = Thread(target=accept_incoming_connections)
      ACCEPT_THREAD.start()
      ACCEPT_THREAD.join()
  SERVER.close()
  </code></pre>