Current location: Hot Scripts Forums » Programming Languages » Perl » checking internet connection


checking internet connection

Reply
  #1 (permalink)  
Old 08-05-05, 11:13 AM
abtimoteo abtimoteo is offline
Newbie Coder
 
Join Date: Dec 2003
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Question checking internet connection

hi, everybody!

how do you check if you are connected to the internet? i would like to do something like the following:

$OS = $^O;

if ($OS eq 'linux' && IF-I-AM-CONNECTED-TO-THE-INTERNET)
{
# send mail to user@mywebsite.com using sendmail.
}
else
{
# send mail to user@localhost using another mail transport agent.
}

thanks!
Reply With Quote
  #2 (permalink)  
Old 08-07-05, 12:46 AM
Chas Chas is offline
Coding Addict
 
Join Date: Oct 2003
Location: California
Posts: 359
Thanks: 0
Thanked 0 Times in 0 Posts
You can use something like Net:ing[1] to try to ping a remote host. As long as the remote host is reachable you're connected. Other than that, your sudo code looks OK to me.

~Charlie

[1] http://search.cpan.org/~bbb/Net-Ping/lib/Net/Ping.pm
Reply With Quote
  #3 (permalink)  
Old 10-02-05, 03:32 PM
sycript sycript is offline
New Member
 
Join Date: Oct 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
re

normally you should use delivery rules from sendmail/qmail/postfix or whatever mta u are using,
alias receiver@localhost:target@localhost , remote@yourdomain.tld
and just send the email from perl script to receiver@localhost using sendmail. mta will take care of delivering the email to both addys, that if u dont mind receiving them to both
otherwise, Mail::Sender, e.g (man page, Single single part message section, a little modified):
$do_local = 0;
$sender = new Mail::Sender {smtp => 'remote domain\'s mx', from => 'you' } or die "$Mail::Sender::Error";
$sender->Open({to=>'remote_address',subject=>''}) or $do_local = 1;
#bla bla msg send
if ($do_local) {
#doit with smtp=>'local domain', to=>'local_address'
}

this will solve not only network connectivity problems but also other smtp-related errors which may appear while talking to remote smtp server. so in case of any error it will be delivered locally. the code should look a little more elegant but im too lazy
see Mail::Sender for more infos
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Finding out the speed of an internet connection xxvatarxx PHP 1 05-12-05 06:32 PM
Check for Internet Connection phppick PHP 3 03-08-05 07:12 PM
ASP syntax error stuckonaproject ASP 8 12-14-04 10:30 AM


All times are GMT -5. The time now is 04:04 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.