Not sure why would you want to do this with ssh. I'm not good with php but here is simple bottle python script for ping and traceroute, I have added auth info also so you would need to run curl from your php page for all server ip's and get output:
from bottle import run, route, request, auth_basic
import os
def login_func(user, passwd):
if user == 'testuser' and passwd == 'testpasswd':
return True
else:
return False
@route('/ping/<ip>')
@auth_basic(login_func)
def ping_func(ip):
request.auth
ping_com = 'ping -c 4 %s' % ip
return os.popen(ping_com)
@route('/traceroute/<ip>')
@auth_basic(login_func)
def traceroute_func(ip):
request.auth
trace_com = 'traceroute %s' % ip
return os.popen(trace_com)
run (host='0.0.0.0', port=8081, debug=False)
to run command from your php you should use this:
curl --user testuser:testpasswd http://server1-IP:8081/ping/1.2.3.4
or
curl --user testuser:testpasswd http://server1-IP:8081/traceroute/1.2.3.4
I think it's safer this way ofc you should change username and password in that script. Simple curl without username and pass will give 401 error, so less chance for someone to abuse service.
Hope this helps.