PHP visit DOS system command

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Charlie of Bolton
    New Member
    • Mar 2007
    • 32

    PHP visit DOS system command

    Hello everyone,

    I want to start a ping on my IP number one, but if this first ip is timing out, I want my script to start automatiquely the check 3 other IP simultanously for comparaison.

    Of course I want the result of the packet lost % to be shown for each of my IPs and that timed out time. What will be your best guest to built such a tool. I`m using PHP 4.x and MySql 4.0 and Windows XP.

    What do you suggest me. »Thanks

    Here is my basic PHP system script and works perfectly:
    -------------------------------------------------------------------------------------------------------------
    [code=php]<?php
    $_ip = $_SERVER['REMOTE_ADDR'];
    echo "<b>Enter the IP or the domain name of the server that you are trying to ping.</b><br>";
    echo "<form method='post' action='ping.ph p?do=ping'><inp ut type='text' name='domain' class='input_lo gin' value='$_ip'>&n bsp;<input type='submit' value='Ping' class='input_lo gin'></form>";
    if($_GET['do'] == 'ping')
    {
    $_domain = $_POST['domain'];
    echo "<pre>";
    //system ("tracert $_domain");
    system ("ping $_domain -n 5");


    echo "</pre>";
    }
    echo "<br>";
    ?>[/code]

    [Please use CODE tags when posting source code. Thanks! --pbmods]
  • luke14free
    New Member
    • Apr 2007
    • 79

    #2
    Hmmm,
    Sorry man, there is no current support in php for +multi+threadin g. But i can suggest you a nice alternative in python. Obviously you can use it just if you create a socket server (if you want that someone else can use your service) and an access sql with the module sqllite(raccome nded :) ). But with those kind of service you have to pay attention to your cpu load!

    PYTHON CODE(yes, i know i am in the php session :) )
    [CODE=python]
    import os
    import re
    import time
    import sys
    from threading import Thread

    class testit(Thread):
    def __init__ (self,ip):
    Thread.__init__ (self)
    self.ip = ip
    self.status = -1
    def run(self):
    pingaling = os.popen("ping -q -c2 "+self.ip," r")
    while 1:
    line = pingaling.readl ine()
    if not line: break
    igot = re.findall(test it.lifeline,lin e)
    if igot:
    self.status = int(igot[0])

    testit.lifeline = re.compile(r"(\ d) received")
    report = ("No response","Part ial Response","Aliv e")

    print time.ctime()

    pinglist = []

    for host in range(60,70):
    ip = "192.168.200."+ str(host)
    current = testit(ip)
    pinglist.append (current)
    current.start()

    for pingle in pinglist:
    pingle.join()
    print "Status from ",pingle.ip,"is ",report[pingle.status]

    print time.ctime()
    [/CODE]

    this code has been taked from http://www.wellho.net
    Have a nice day

    Comment

    • Charlie of Bolton
      New Member
      • Mar 2007
      • 32

      #3
      Thanks, I will take a look in Python and your ref web site.
      I appreciated your reply.

      Merci/Charlie

      --------------------------------------------------------------------------------

      Originally posted by luke14free
      Hmmm,
      Sorry man, there is no current support in php for +multi+threadin g. But i can suggest you a nice alternative in python. Obviously you can use it just if you create a socket server (if you want that someone else can use your service) and an access sql with the module sqllite(raccome nded :) ). But with those kind of service you have to pay attention to your cpu load!

      PYTHON CODE(yes, i know i am in the php session :) )
      [CODE=python]
      import os
      import re
      import time
      import sys
      from threading import Thread

      class testit(Thread):
      def __init__ (self,ip):
      Thread.__init__ (self)
      self.ip = ip
      self.status = -1
      def run(self):
      pingaling = os.popen("ping -q -c2 "+self.ip," r")
      while 1:
      line = pingaling.readl ine()
      if not line: break
      igot = re.findall(test it.lifeline,lin e)
      if igot:
      self.status = int(igot[0])

      testit.lifeline = re.compile(r"(\ d) received")
      report = ("No response","Part ial Response","Aliv e")

      print time.ctime()

      pinglist = []

      for host in range(60,70):
      ip = "192.168.200."+ str(host)
      current = testit(ip)
      pinglist.append (current)
      current.start()

      for pingle in pinglist:
      pingle.join()
      print "Status from ",pingle.ip,"is ",report[pingle.status]

      print time.ctime()
      [/CODE]

      this code has been taked from http://www.wellho.net
      Have a nice day

      Comment

      Working...