Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Sat 25 Oct 2014, 05:17
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
Verify if Internet connection is duly active? [SOLVED]
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
Page 1 of 1 Posts_count  
Author Message
Argolance


Joined: 06 Jan 2008
Posts: 1839
Location: PORT-BRILLET (Mayenne - France)

PostPosted: Tue 05 Mar 2013, 10:04    Post_subject:  Verify if Internet connection is duly active? [SOLVED]  

Hello,
Before executing a script, I need a (simple) command line to know if and be absolutely sure that user's Internet connexion is actually active...
Thank you.

Cordialement.

Edited_time_total
Back to top
View user's profile Send_private_message Visit_website 
L18L

Joined: 19 Jun 2010
Posts: 2530
Location: Moved from Hosla to www.eussenheim.de

PostPosted: Tue 05 Mar 2013, 11:30    Post_subject: Verify if Internet connection is duly active?  

Code:
 [ "`ifconfig | head -n 1| awk '{print $1}'`" = "lo" ] && echo no || echo oui

Wink

lo is local loopback
if this is at first place then no other connection exists

---
edited: forget it, take vovchik's

Edited_time_total
Back to top
View user's profile Send_private_message 
Argolance


Joined: 06 Jan 2008
Posts: 1839
Location: PORT-BRILLET (Mayenne - France)

PostPosted: Tue 05 Mar 2013, 11:34    Post_subject:  

Thanks you! Very Happy
Back to top
View user's profile Send_private_message Visit_website 
vovchik


Joined: 23 Oct 2006
Posts: 1285
Location: Ukraine

PostPosted: Tue 05 Mar 2013, 11:48    Post_subject:  

Dear L18L,

That isn't true in my case:
Code:

root$ [~]-> ifconfig           
lo        Link encap:Local Loopback 
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:976 errors:0 dropped:0 overruns:0 frame:0
          TX packets:976 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:71960 (70.2 KiB)  TX bytes:71960 (70.2 KiB)

wlan0     Link encap:Ethernet  HWaddr D8:F8:BA:D8:F8:BA 
          inet addr:192.168.0.16  Bcast:192.168.0.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:93463 errors:0 dropped:0 overruns:0 frame:0
          TX packets:98017 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:53415279 (50.9 MiB)  TX bytes:12026226 (11.4 MiB)


This seems to work for me:

Code:
#!/usr/bin/bash

# Test for network conection
for interface in $(ls /sys/class/net/ | grep -v lo);
do
   if [[ "$(cat /sys/class/net/$interface/operstate)" == "up" ]]; then
      echo "Online: $interface"
      OnLine=1
   fi
done
if ! [ $OnLine ]; then echo "Not Online" > /dev/stderr; exit; fi


or

There are also some nice methods using netstat -punt or netstat -natu and lsof -i.

With kind regards,
vovchik
Back to top
View user's profile Send_private_message 
L18L

Joined: 19 Jun 2010
Posts: 2530
Location: Moved from Hosla to www.eussenheim.de

PostPosted: Tue 05 Mar 2013, 11:54    Post_subject:  

@Argolance,
I am sorry
fast solutions are not always right solutions Laughing

@vovchik,
your script works for me too Smile

Edited_time_total
Back to top
View user's profile Send_private_message 
Argolance


Joined: 06 Jan 2008
Posts: 1839
Location: PORT-BRILLET (Mayenne - France)

PostPosted: Tue 05 Mar 2013, 12:11    Post_subject:  

@L18L
Your code line worked for me!
Quote:
I am sorry

Don't!
Thank you to both of you.

Cordialement.
Back to top
View user's profile Send_private_message Visit_website 
L18L

Joined: 19 Jun 2010
Posts: 2530
Location: Moved from Hosla to www.eussenheim.de

PostPosted: Tue 05 Mar 2013, 12:22    Post_subject: Verify if Internet connection is duly active?[otherSOLUTION]
Sub_title: one liner
 

Code:
[ $(grep up /sys/class/net/*/operstate) ] && echo online

other values in operstate:
-down
-unknown (for lo)
Back to top
View user's profile Send_private_message 
vovchik


Joined: 23 Oct 2006
Posts: 1285
Location: Ukraine

PostPosted: Tue 05 Mar 2013, 12:32    Post_subject:  

Dear L18L,

I like your last one - works nicely and is a one-liner:)

With kind regards,
vovchik
Back to top
View user's profile Send_private_message 
Argolance


Joined: 06 Jan 2008
Posts: 1839
Location: PORT-BRILLET (Mayenne - France)

PostPosted: Tue 05 Mar 2013, 12:42    Post_subject:  

Quote:
I like your last one - works nicely and is a one-liner
Yes indeed!
Back to top
View user's profile Send_private_message Visit_website 
Argolance


Joined: 06 Jan 2008
Posts: 1839
Location: PORT-BRILLET (Mayenne - France)

PostPosted: Tue 23 Apr 2013, 06:16    Post_subject:  

Hello,
While running a fresh install of Puppy on a friend's PC, I succeeded in setting the wifi Internet connection and was able to go on the Internet with the web browser... But the command used in one of my scripts:
Code:
if [ $(grep down /sys/class/net/*/operstate) ]; then
Xdialog --title "$(eval_gettext '$app Installation') - $(gettext 'Information')" --icon /usr/local/lib/X11/pixmaps/info.png --msgbox "$(eval_gettext 'Your internet connection seems not to be active.
Please, set it up before downloading/installing $app!')" 0 0
else
[...]

... that lets user download applications from a remote server, said the connexion was not active... Shocked Embarassed
So it seems this command is not absolutely sure: what I am obviously expecting for!

Is there any other command (using ping Rolling Eyes ?) doing this "properly"?

Cordialement.
Back to top
View user's profile Send_private_message Visit_website 
Argolance


Joined: 06 Jan 2008
Posts: 1839
Location: PORT-BRILLET (Mayenne - France)

PostPosted: Tue 23 Apr 2013, 09:35    Post_subject:  

Hello,
Found this which works fine:
Code:
#!/bin/sh

curl -D- -o /dev/null -s http://xxxxx.net
if [[ $? == 0 ]]; then
  echo "yes"
else
  echo "no"
fi


Cordialement!
Back to top
View user's profile Send_private_message Visit_website 
L18L

Joined: 19 Jun 2010
Posts: 2530
Location: Moved from Hosla to www.eussenheim.de

PostPosted: Tue 23 Apr 2013, 09:44    Post_subject:  

Found this:
Code:
PING="`ping -c 1 xxxxx.net `"
 [ "${PING:0:4}" = "PING"  ] && echo online

Not every server responds on pings
Back to top
View user's profile Send_private_message 
Argolance


Joined: 06 Jan 2008
Posts: 1839
Location: PORT-BRILLET (Mayenne - France)

PostPosted: Tue 23 Apr 2013, 09:50    Post_subject:  

OK, thanks!
Back to top
View user's profile Send_private_message Visit_website 
Display_posts:   Sort by:   
Page 1 of 1 Posts_count  
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
 Forum index » Off-Topic Area » Programming
Jump to:  

Rules_post_cannot
Rules_reply_cannot
Rules_edit_cannot
Rules_delete_cannot
Rules_vote_cannot
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0736s ][ Queries: 12 (0.0084s) ][ GZIP on ]