473,769 Members | 5,823 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PHP visit DOS system command

32 New Member
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:
-------------------------------------------------------------------------------------------------------------
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $_ip = $_SERVER['REMOTE_ADDR'];
  3. echo "<b>Enter the IP or the domain name of the server that you are trying to ping.</b><br>";
  4. echo "<form method='post' action='ping.php?do=ping'><input type='text' name='domain' class='input_login' value='$_ip'>&nbsp;<input type='submit' value='Ping' class='input_login'></form>";
  5. if($_GET['do'] == 'ping')
  6. {
  7. $_domain = $_POST['domain'];
  8.         echo "<pre>";
  9.                     //system ("tracert $_domain");
  10.                    system ("ping $_domain -n 5");
  11.  
  12.  
  13.           echo "</pre>";
  14. }
  15. echo "<br>";
  16.  ?>
[Please use CODE tags when posting source code. Thanks! --pbmods]
Jul 2 '07 #1
2 1667
luke14free
79 New Member
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 :) )
Expand|Select|Wrap|Line Numbers
  1. import os
  2. import re
  3. import time
  4. import sys
  5. from threading import Thread
  6.  
  7. class testit(Thread):
  8.    def __init__ (self,ip):
  9.       Thread.__init__(self)
  10.       self.ip = ip
  11.       self.status = -1
  12.    def run(self):
  13.       pingaling = os.popen("ping -q -c2 "+self.ip,"r")
  14.       while 1:
  15.         line = pingaling.readline()
  16.         if not line: break
  17.         igot = re.findall(testit.lifeline,line)
  18.         if igot:
  19.            self.status = int(igot[0])
  20.  
  21. testit.lifeline = re.compile(r"(\d) received")
  22. report = ("No response","Partial Response","Alive")
  23.  
  24. print time.ctime()
  25.  
  26. pinglist = []
  27.  
  28. for host in range(60,70):
  29.    ip = "192.168.200."+str(host)
  30.    current = testit(ip)
  31.    pinglist.append(current)
  32.    current.start()
  33.  
  34. for pingle in pinglist:
  35.    pingle.join()
  36.    print "Status from ",pingle.ip,"is",report[pingle.status]
  37.  
  38. print time.ctime()
  39.  
this code has been taked from http://www.wellho.net
Have a nice day
Jul 2 '07 #2
Charlie of Bolton
32 New Member
Thanks, I will take a look in Python and your ref web site.
I appreciated your reply.

Merci/Charlie

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

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 :) )
Expand|Select|Wrap|Line Numbers
  1. import os
  2. import re
  3. import time
  4. import sys
  5. from threading import Thread
  6.  
  7. class testit(Thread):
  8.    def __init__ (self,ip):
  9.       Thread.__init__(self)
  10.       self.ip = ip
  11.       self.status = -1
  12.    def run(self):
  13.       pingaling = os.popen("ping -q -c2 "+self.ip,"r")
  14.       while 1:
  15.         line = pingaling.readline()
  16.         if not line: break
  17.         igot = re.findall(testit.lifeline,line)
  18.         if igot:
  19.            self.status = int(igot[0])
  20.  
  21. testit.lifeline = re.compile(r"(\d) received")
  22. report = ("No response","Partial Response","Alive")
  23.  
  24. print time.ctime()
  25.  
  26. pinglist = []
  27.  
  28. for host in range(60,70):
  29.    ip = "192.168.200."+str(host)
  30.    current = testit(ip)
  31.    pinglist.append(current)
  32.    current.start()
  33.  
  34. for pingle in pinglist:
  35.    pingle.join()
  36.    print "Status from ",pingle.ip,"is",report[pingle.status]
  37.  
  38. print time.ctime()
  39.  
this code has been taked from http://www.wellho.net
Have a nice day
Jul 2 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
2041
by: Nicolas Fleury | last post by:
Hi, How can I know if a system command doesn't exist? All the ways I have tried behave like if the system command was existing but returning one. I don't want to sound provocative, but open in Perl returns an error in a command doesn't exist, so I'm sure we could have an exception in the same case for popen in Python? Thx and Regards, Nicolas
15
7925
by: Sokar | last post by:
Hello, I am writing a script which is using the system() command. In the script the system command invokes an encryption with system("gpg -f file.txt"). The problem comes when the script is required to perform this operation on different files which the user selects via another function. The name of the filename is stored in a variable as a string and I can't get the variable substituted into the ststem
6
1815
by: jsw_nz | last post by:
Helo, my first post here.... I am trying to run an agent application that converts and imports two tables from MS Access into mySql. (Intelligent Converters - Access2mySql) I have run similar scripts to do mysql dumps using the system function. Not sure if the paths included in the parameters are correct: <?php function import_data() {
1
2947
by: darren kirby | last post by:
Hello all. I have a python script here which is just a wrapper for 2 or more system commands. I would estimate the program spends at least 95.5% of 'real' time running the system commands. I want to trap the key combo and exit (somewhat) gracefully if the user decides to abort the program. I am using os.system for the system call, and I have wrapped the entire main loop in a try: except KeyboardInterrupt statement to try to...
11
2734
by: jobs239 | last post by:
Can I use this line inside C program "system(java -jar <jarfilename>)" to run a java program from C? Or do I have to use some JNI interface.?
3
2646
by: pavi | last post by:
Hi, I am using system command to execute a shell script in a C program. Usage system("sh file"). There are situations where the file may be empty. But execution gets hung if the file is empty. What might be the problem. Regards, Praveen Kumar A.S
8
10376
by: jkeith07 | last post by:
Ok so ive reached the end of my knowledge and have tried to find out how to do it and just plain dont understand it. I have a system call: system("db2cmd.exe \"db2 connect to vop9 user joebloggs using joesPassword&&db2 LOAD FROM \"d:\\vop9\\records_test.csv\" OF DEL MODIFIED BY COLDEL; METHOD P (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17) MESSAGES \"D:\\vop9\\output.txt\" INSERT INTO UKVOICE.CALLDATA (ID, REFERENCE,...
1
3193
by: python1 | last post by:
Hi All, I am using a python system command to execute a C++ executable file which takes certain binary input. For example: C++ exe name is "Test" "Test" takes the following input . '\x02\xfa\xcbQH\x00' command = '/opt/etc/Test %s' % ('\x02\xfa\xcbQH\x00') system command I am using is : os.popen(command)
4
2693
by: boriq | last post by:
Hi, I'm using in my script command os.system('command') on Windows XP. Each time the os.system command is used, python opens an empty ms-dos command window (the black one) and then closes it. So when in one script the os.system command 50 times is used, I see 50 black windows. Is there a way of how to suppress this unnecessary command windows to be opened?
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10043
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9990
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9861
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8869
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7406
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5298
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5446
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.