How to make ping website ip using PHP? [duplicate] - ping

This question already has answers here:
Pinging an IP address using PHP and echoing the result
(11 answers)
Closed 4 years ago.
I'm working on a small php script and i'd like to add ping feature to the script. I really don't know how to do it but , i like to have the same result as this : http://www.ipfingerprints.com/ping.php

Depending on the permissions in php, you might be able to
<?php system("ping -c 3 localhost"); ?>
Be very careful accepting hostnames from web forms - if a user requests that you ping the server "; rm -rf /", you will lose all your data!

it is very simple
<?php
if (!$socket = #fsockopen("YOUR.IP.HERE", 80, $errno, $errstr, 30))
{
echo "<font color='red'><strong>Offline!</strong></font>";
}
else
{
echo "<font color='green'><strong>Online!/strong></font>";
fclose($socket);
}
?>

Or use this code " exec('ping -c '.$pingTimes.'.$ipAdress); " at PHP

If you want to have real ping (send ICMP packets) you can take a look at this Native-PHP ICMP ping implementation, but I didn't test it.

Related

(WAMP/XAMP) send Mail using SMTP localhost [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
How to send mail from localhost SMTP (using Wamp,Xampp or etc..)? PHP mail() doesn't seem to work natively.
Can anybody give the instructions?
Method 1 (Preferred) - Using hMailServer
After installation, you need the following configuration to properly send mail from wampserver:
1) When you first open hMailServer Administrator, you need to add a new domain.
2) Click on the "Add Domain ..." button at the Welcome page.
3) Under the domain text field, enter your computer's IP, in this case it should be 127.0.0.1.
4) Click on the Save button.
5) Go to Settings>Protocols>SMTP and select "Delivery of Email" tab
6) Enter "localhost" in the localhost name field.
7) Click on the Save button.
If you need to send mail using a FROM addressee of another computer, you need to allow deliveries from External to External accounts. To do that, follow these steps:
1) Go to Settings>Advanced>IP Ranges and double click on "My Computer" which should have IP address of 127.0.0.1
2) Check the Allow Deliveries from External to External accounts checkbox.
3) Save settings using Save button.
(However, Windows Live/Hotmail has denied all emails coming from dynamic IPs, which most residential computers are using. The workaround is to use Gmail account )
Note to use Gmail users :
1) Go to Settings>Protocols>SMTP and select "Delivery of Email" tab
2) Enter "smtp.gmail.com" in the Remote Host name field.
3) Enter "465" as the port number
4) Check "Server requires authentication"
5) Enter gmail address in the Username
6) Enter gmail password in the password
7) Check "Use SSL"
(Note, From field doesnt function with gmail)
*p.s. For some people it might also be needed to untick everything under require SMTP authentication in :
for local : Settings>Advanced>IP Ranges>"My Computer"
for external : Settings>Advanced>IP Ranges>"Internet"
Method 2 - Using SendMail
You can use SendMail installation.
Method 3 - Using different methods
Use any of these methods.
Here's the steps to achieve this:
Download the sendmail.zip through this link
Now, extract the folder and put it to C:/wamp/. Make sure that these four files are present: sendmail.exe, libeay32.dll, ssleay32.ddl and sendmail.ini.
Open sendmail.ini and set the configuration as follows:
smtp_server=smtp.gmail.com
smtp_port=465
smtp_ssl=ssl
default_domain=localhost
error_logfile=error.log
debug_logfile=debug.log
auth_username=[your_gmail_account_username]#gmail.com
auth_password=[your_gmail_account_password]
pop3_server=
pop3_username=
pop3_password=
force_sender=
force_recipient=
hostname=localhost
Access your email account. Click the Gear Tool > Settings > Forwarding and POP/IMAP > IMAP access. Click "Enable IMAP", then save your changes.
Run your WAMP Server. Enable ssl_module under Apache Module.
Next, enable php_openssl and php_sockets under PHP.
Open php.ini and configure it as the codes below. Basically, you just have to set the sendmail_path.
[mail function]
; For Win32 only.
; http://php.net/smtp
;SMTP =
; http://php.net/smtp-port
;smtp_port = 25
; For Win32 only.
; http://php.net/sendmail-from
;sendmail_from = you#domain.com
; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
sendmail_path = "C:\wamp\sendmail\sendmail.exe -t -i"
Restart Wamp Server
I hope this will work for you..
You can use this library to send email ,if having issue with local xampp,wamp...
class.phpmailer.php,class.smtp.php
Write this code in file where your email function calls
include('class.phpmailer.php');
$mail = new PHPMailer();
$mail->IsHTML(true);
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl";
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->Username = "your email ID";
$mail->Password = "your email password";
$fromname = "From Name in Email";
$To = trim($email,"\r\n");
$tContent = '';
$tContent .="<table width='550px' colspan='2' cellpadding='4'>
<tr><td align='center'><img src='imgpath' width='100' height='100'></td></tr>
<tr><td height='20'> </td></tr>
<tr>
<td>
<table cellspacing='1' cellpadding='1' width='100%' height='100%'>
<tr><td align='center'><h2>YOUR TEXT<h2></td></tr/>
<tr><td> </td></tr>
<tr><td align='center'>Name: ".trim(NAME,"\r\n")."</td></tr>
<tr><td align='center'>ABCD TEXT: ".$abcd."</td></tr>
<tr><td> </td></tr>
</table>
</td>
</tr>
</table>";
$mail->From = "From email";
$mail->FromName = $fromname;
$mail->Subject = "Your Details.";
$mail->Body = $tContent;
$mail->AddAddress($To);
$mail->set('X-Priority', '1'); //Priority 1 = High, 3 = Normal, 5 = low
$mail->Send();
you can directly send mail from php mail() function if you specified the smtp server and smtp port in php.ini, first ask the SMTP server credential to your ISP.
SMTP = smtp.wlink.com.np //put your ISP's smtp server
smtp_port = 25 // your ISP's smtp port.
then just restart the apache server and it will start working. ENjoy ...
I prefer using PHPMailer script to send emails from localhost as it lets me use my Gmail account as SMTP. You can find the PHPMailer from http://phpmailer.worxware.com/ . Help regarding how to use gmail as SMTP or any other SMTP can be found at http://www.mittalpatel.co.in/php_send_mail_from_localhost_using_gmail_smtp . Hope this helps!
If any one of you are getting error like following after following answer given by Afwe Wef
Warning: mail() [<a href='function.mail'>function.mail</a>]: SMTP server response:
550 The address is not valid. in c:\wamp\www\email.php
Go to php.ini
; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = valideaccount#gmail.com
Enter valideaccount#gmail.com as your email id which you used to configure the hMailserver in front of sendmail_from .
your problem will be solved.
Tested on Wamp server2.2(Apache 2.2.22, php 5.3.13) on windows 8
If you are also getting following error
"APPLICATION" 6364 "2014-03-24 13:13:33.979" "SMTPDeliverer - Message 2: Relaying to host smtp.gmail.com."
"APPLICATION" 6364 "2014-03-24 13:13:34.415" "SMTPDeliverer - Message 2: Message could not be delivered. Scheduling it for later delivery in 60 minutes."
"APPLICATION" 6364 "2014-03-24 13:13:34.430" "SMTPDeliverer - Message 2: Message delivery thread completed."
You might have forgot to change the port from 25 to 465

TCL program to login to a remote server and excute command

I need to write a TCL program through which I shall be able to login to the remote server and then execute commands on the remote server; also I need to get the output from the remote server.
EDIT:
Thanks Kostix for the reply. My requirement says that the TCL script should be able to login to the remote server. I am planning to send the password thru the expect mechanism, and after that I am planning to send the commands. My sample code goes like this:
set prompt "(%|>|\#|\\\$) #"
spawn /usr/bin/ssh $username#$server
expect {
-re "Are you sure you want to continue connecting (yes/no)?" {
exp_send "yes\r"
exp_continue
#continue to match statements within this expect {}
}
-nocase "password: " {
exp_send "$password\r"
interact
}
}
I am able to login with this but dont know how to extend this code to send commands. I've tried few methods, but didn't work out.
Since you're about to use SSH, you might not need neither Tcl nor Expect to carry out this task at all: since SSH stands for "Secure SHell", all you need to do to execute commands remotely is to tell SSH what program to spawn on the remote side after logging in (if you do not do this, SSH spawns the so-called "login shell" of the logged in user) and then SSH feeds that program what you pass the SSH client on its standard input and channels back what the remote program writes to its standard output streams.
To automate logging via SSH, several ways exist:
Authentication using public keys: if the private (client's) key is not protected by a password, this method requires no scripting at all — you just tell the SSH client what key to use.
"Keyboard interactive" authentication (password-based). This is what most people think SSH is all about (which is wrong). Scripting this is somewhat hard as SSH insists on getting the password from a "real terminal". It can be tricked to beleive so either through using Expect or simply by wrapping a call to the SSH client using the sshpass program.
Both the SSH client and the server might also support Kerberos-based or GSSAPI-based authentication. Using it might not require any scripting as it derives the authentication credentials from the system (the local user's session).
So the next steps to carry out would be to narrow your requirements:
What kind of authentication has to be supported?
What program should perform the commands you intend to send from the client? Will that be a Unix shell? A Tcl shell? Something else?
Should that remote command be scripted using some degree of interactivity (we send something to it then wait for reply and decide what to send next based on it) or batch-style script would be okay?
Before these questions are answered, the inital question has little sense as it's too broad and hence does not meet stackoverflow format.
Commands on the server can be executed either using exec command like this,
set a [exec ls -lrta]
puts $a
[OR] The expect and execute loop can be continued as above;
I am making a proc using which linux commands can easily be run;
package require Expect
proc ExecCommand {username server password cmd } {
spawn /usr/bin/ssh $username#$server
expect {
".*(yes/no)? " {exp_send "yes\r" ; exp_continue}
".*password: " {exp_send "$password\r";exp_continue}
".*$ " {exp_send -i $spawn_id "$cmd \r";
expect {
".*$ " { return 1; close }
}
}
}
}
set result [ExecCommand "admin" "0" "qwerty" "ls"]
if {$result > 0 } {
puts "Command succesfully executed\n"
} else {
puts "Failed to execute\n"
}

MySql - replication monitoring tool [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
I have a master/slave MySql replication.
Im looking for a tool that will allow me to monitor the replication (see it has no error, check on the lag, etc.)
I prefer a visual tool that will allow all team members get visibility on the status and not a script tool.
any ideas?
We are using the following bash script. You could do the same idea in php and web base the code.
#!/bin/sh
## Joel Chaney##
## joel.chaney#mongoosemetrics.com (look at robots.txt) ##
## 2012-02-03 ##
repeat_alert_interval=30 # minutes for lock file life
lock_file=/tmp/slave_alert.lck # location of lock file
EMAIL=YOURNAME#YOURCOMPANY.DOM # where to send alerts
SSTATUS=/tmp/sstatus # location of sstatus file
### Code -- do not edit below ##
NODE=`uname -n`
## Check if alert is locked ##
function check_alert_lock () {
if [ -f $lock_file ] ; then
current_file=`find $lock_file -cmin -$repeat_alert_interval`
if [ -n "$current_file" ] ; then
# echo "Current lock file found"
return 1
else
# echo "Expired lock file found"
rm $lock_file
return 0
fi
else
touch $lock_file
return 0
fi
}
SLAVE=mysql
$SLAVE -e 'SHOW SLAVE STATUS\G' > $SSTATUS
function extract_value {
FILENAME=$1
VAR=$2
grep -w $VAR $FILENAME | awk '{print $2}'
}
Master_Binlog=$(extract_value $SSTATUS Master_Log_File )
Master_Position=$(extract_value $SSTATUS Exec_Master_Log_Pos )
Master_Host=$(extract_value $SSTATUS Master_Host)
Master_Port=$(extract_value $SSTATUS Master_Port)
Master_Log_File=$(extract_value $SSTATUS Master_Log_File)
Read_Master_Log_Pos=$(extract_value $SSTATUS Read_Master_Log_Pos)
Slave_IO_Running=$(extract_value $SSTATUS Slave_IO_Running)
Slave_SQL_Running=$(extract_value $SSTATUS Slave_SQL_Running)
Slave_ERROR=$(extract_value $SSTATUS Last_Error)
ERROR_COUNT=0
if [ "$Master_Binlog" != "$Master_Log_File" ]
then
ERRORS[$ERROR_COUNT]="master binlog ($Master_Binlog) and Master_Log_File ($Master_Log_File) differ"
ERROR_COUNT=$(($ERROR_COUNT+1))
fi
POS_DIFFERENCE=$(echo ${Master_Position}-${Read_Master_Log_Pos}|bc)
if [ $POS_DIFFERENCE -gt 1000 ]
then
ERRORS[$ERROR_COUNT]="The slave is lagging behind of $POS_DIFFERENCE"
ERROR_COUNT=$(($ERROR_COUNT+1))
fi
if [ "$Slave_IO_Running" == "No" ]
then
ERRORS[$ERROR_COUNT]="Replication is stopped"
ERROR_COUNT=$(($ERROR_COUNT+1))
fi
if [ "$Slave_SQL_Running" == "No" ]
then
ERRORS[$ERROR_COUNT]="Replication (SQL) is stopped"
ERROR_COUNT=$(($ERROR_COUNT+1))
fi
if [ $ERROR_COUNT -gt 0 ]
then
if [ check_alert_lock == 0 ]
then
SUBJECT="${NODE}-ERRORS in replication"
BODY=''
CNT=0
while [ "$CNT" != "$ERROR_COUNT" ]
do
BODY="$BODY ${ERRORS[$CNT]}"
CNT=$(($CNT+1))
done
BODY=$BODY" \n${Slave_ERROR}"
echo $BODY | mail -s "$SUBJECT" $EMAIL
fi
else
echo "Replication OK"
fi
#!/bin/bash
HOST=your-server-ip
USER=mysql-user
PASSWORD=mysql-password
SUBJECT="Mysql replication problem"
EMAIL=your#email.address
RESULT=`mysql -h $HOST -u$USER -p$PASSWORD -e 'show slave status\G' | grep Last_SQL_Error | sed -e 's/ *Last_SQL_Error: //'`
if [ -n "$RESULT" ]; then
echo "$RESULT" | mail -s "$SUBJECT" $EMAIL
fi
You can use any programming language to query mysql and fetch the results from:
show slave status; <-- execute on slave
show master status; <-- execute on master
If you think this is a bad idea, then install phpmyadmin, there is an already built-in GUI for replication monitoring, like: http://demo.phpmyadmin.net/master-config/ (replication)
If you're just interested in whether the slave is up to date or not:
mysql 'your connection info' -e 'show slave status\G' | grep -i seconds_behind
I've used a few different approaches, the most basic being using a PHP web page to check the slave status, and then getting standard monitoring tools to monitor the page. This is a nice approach as it means your existing monitoring tools can be used for alerts by checking the web page.
Example: to check the status of a database server at host db1.internal
http://mywebserver.com/replicationtest.php?host=db1.internal
Should always return "Yes"
replicationtest.php:
<?php
$username="myrepadmin";
$password="";
$database="database";
mysql_connect($_REQUEST['host'],$username,$password);
#mysql_select_db($database) or die( "Unable to select database");
$query="show slave status;";
$result=mysql_query($query);
$arr = mysql_fetch_assoc($result);
echo $arr['Slave_SQL_Running'] ;
mysql_close();
?>
You could also monitor Seconds_Behind_Master, Last_IO_Errno, Last_SQL_Errno etc.
You can monitor this web page externally, or add it into many standard monitoring tools that can check a web page. I've used free service http://monitor.us
Alternatively, if you don't mind running code from 3rd parties on your internal infrastructure http://newrelic.com offer great server monitoring tools with a web interface, and include a MySQL plugin that provides lots of great info such as Query Analysis, InnoDB metrics and Replication status with lag monitors. New Relic specialise on web app monitoring but the free service allows you to monitor an unlimited number of servers.
I currently use a combination of these tools with the above web page being used to trigger alerts for emergencies, and the NewRelic tools for viewing long term performance and trend analysis.
The question is:
do you want to know if your Mysql replication is OK
OR do you want to know if your data are consistent ?
You can't rely only on SHOW SLAVE STATUS output to know if your slave is identical to Master: a (bad) try to solve an error that halted your replication may imply that some INSERT or UPDATE or whatever, never occured on your slave.
To check this you have to read SHOW SLAVE STATUS, of course, everything has to be ok in that output, but you also have to compare data (ie number of rows, checksum, ...).
I've written a PHP tool to do that: https://bitbucket.org/verticalassertions/verticalslave
It features :
check replication (checks on show slave status values, check table, checksum table, ...)
check replication with auto-repair (same as above + dump of replicated tables in errors)
dump of non-replicated databases (listed in config)
reset replication when you broke all to the ground - basically a dump of replicated databases and start slave)
send shorten report by mail, link to full report on website version
store past reports
can be run from CLI (crontab) or manually from website you set up
Feel free to fork and improve. I'm sure some tools are better (especially in layout xD ), but I needed a tool that does exactly what I ask and no fancy things I couldn't figure.

How can I display if a process is running on my web page?

I want to be able to display on my web page whether or not a process is running. Both run on the same system (Ubuntu server).
Basically, if something like the command ps -u game | grep java returns something, I want the site to display something like "Game Server Online", else "Offline."
I figure I could redirect the grep output to a file every 5 mins and have a script on the main page read the file content as a string to determine what to print. I feel as though there is be a much better way to do this, however. What else could I do and which scripting language would be best for this task?
If php is available, you could do something like this inline in your page:
<?php
$output = shell_exec('ps -u game | grep java');
if ($output === "java something") {
echo "Server running"
} else {
echo "Server not running"
}
?>
what about a simple web service call?
calling a web service would ensure that both the server is up and the process is running.

How to figure out the SMTP server host? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 1 year ago.
The community reviewed whether to reopen this question 1 year ago and left it closed:
Original close reason(s) were not resolved
Improve this question
I am using SMTP to send emails by PHP.
My client has a shared hosting.
I created an email account there.
There is no information available about what will be the SMTP server for this account.
I have tried: smtp.domainname.com
But it's not able to connect.
How can I figure out my SMTP server host? any idea?
this really is a question for Serverfault.
Windows:
Open up a command prompt (CMD.exe)
Type nslookup and hit enter
Type set type=MX and hit enter
Type the domain name and hit enter, for example: google.com
The results will be a list of host names that are set up for SMTP
Linux:
Open a command prompt
Type dig domain.name MX and hit enter where domain.name is the domain you are trying to find out the smtp server for.
If you do not get any answers back from your dns server, there is a good chance that there isn't any SMTP Servers set up for that domain. If this is the case, do like other's have suggested and call the hosting companies tech support.
generally smtp servers name are smtp.yourdomain.com or mail.yourdomain.com
open command prompt try to run following two commands
>ping smtp.yourdomain.com
>ping mail.yourdomain.com
you will most probably get response from any one from the above two commands.and that will be your smtp server
If this doesn't work open your cpanel --> go to your mailing accounts -- > click on configure mail account -- > there somewhere in the page you will get the information about your smtp server
it will be written like this way may be :
Incoming Server: mail.yourdomain.com
IMAP Port: ---
POP3 Port: ---
Outgoing Server: mail.yourdomain.com
SMTP Port: ---
You could send yourself an email an look in the email header (In Outlook: Open the mail, View->Options, there is 'Internet headers)
You can use the dig/host command to look up the MX records to see which mail server is handling mails for this domain.
On Linux you can do it as following for example:
$ host google.com
google.com has address 74.125.127.100
google.com has address 74.125.67.100
google.com has address 74.125.45.100
google.com mail is handled by 10 google.com.s9a2.psmtp.com.
google.com mail is handled by 10 smtp2.google.com.
google.com mail is handled by 10 google.com.s9a1.psmtp.com.
google.com mail is handled by 100 google.com.s9b2.psmtp.com.
google.com mail is handled by 10 smtp1.google.com.
google.com mail is handled by 100 google.com.s9b1.psmtp.com.
(as you can see, google has quite a lot of mail servers)
If you are working with windows, you might use nslookup (?) or try some web tool (e.g. that one) to display the same information.
Although that will only tell you the mail server for that domain. All other settings which are required can't be gathered that way. You might have to ask the provider.
To automate the answer of #Jordan S. Jones at WIN/DOS command-line,
Put this in a batch file named: getmns.bat (get mail name server):
#echo off
if #%1==# goto USAGE
echo set type=MX>mnscmd.txt
echo %1>>mnscmd.txt
echo exit>>mnscmd.txt
nslookup<mnscmd.txt>mnsresult.txt
type mnsresult.txt
del mnsresult.txt
goto END
:USAGE
echo usage:
echo %0 domainname.ext
:END
echo.
For example:
getmns google.com
output:
google.com MX preference = 20, mail exchanger = alt1.aspmx.l.google.com
google.com MX preference = 10, mail exchanger = aspmx.l.google.com
google.com MX preference = 50, mail exchanger = alt4.aspmx.l.google.com
google.com MX preference = 40, mail exchanger = alt3.aspmx.l.google.com
google.com MX preference = 30, mail exchanger = alt2.aspmx.l.google.com
alt4.aspmx.l.google.com internet address = 74.125.25.27
alt3.aspmx.l.google.com internet address = 173.194.72.27
aspmx.l.google.com internet address = 173.194.65.27
alt1.aspmx.l.google.com internet address = 74.125.200.27
alt2.aspmx.l.google.com internet address = 64.233.187.27
For example to pipe the result again into a file do:
getmns google.com > google.mns.txt
:-D
Quick example:
On Ubuntu, if you are interested, for instance, in Gmail then open the Terminal and type:
nslookup -q=mx gmail.com