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 Wed 19 Dec 2018, 01:46
All times are UTC - 4
 Forum index » Advanced Topics » Additional Software (PETs, n' stuff) » Network
Test Net Connection without ping
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [14 Posts]  
Author Message
stemsee

Joined: 27 Jun 2013
Posts: 2277
Location: In The Way

PostPosted: Tue 23 Jan 2018, 09:48    Post subject:  Test Net Connection without ping  

Simple script to test connection without resorting to ping.

Code:
#!/bin/sh
# Test for network conection without ping
# adapted from https://bbs.archlinux.org/viewtopic.php?id=55485
#
for interface in $(ls /sys/class/net/ | grep -v lo);
do
   if [[ $(cat /sys/class/net/$interface/carrier) = 1 ]]; then
      OnLine="Online"
   elif [[  $(cat /sys/class/net/$interface/carrier) = 0 ]]; then
      OnLine="Not Online"
   fi
done
export OnLine
echo "$OnLine"
yad --text="$OnLine" --timeout=1
Back to top
View user's profile Send private message MSN Messenger 
sheldonisaac

Joined: 21 Jun 2009
Posts: 776
Location: Philadelphia, PA

PostPosted: Tue 23 Jan 2018, 10:23    Post subject: Re: Test Net Connection without ping  

stemsee (in part) wrote:
Simple script to test connection without resorting to ping.
Thank you, stemsee!

Sheldon

_________________
Dell E6410: Xenial, Bionicpup64, etc
Dell Mini 9, Acer Aspire One, EeePC 1018P, PowerBook G4
Intel D865GBF, Intel DQ35JOE
Back to top
View user's profile Send private message 
stemsee

Joined: 27 Jun 2013
Posts: 2277
Location: In The Way

PostPosted: Tue 23 Jan 2018, 11:44    Post subject: Re: Test Net Connection without ping  

sheldonisaac wrote:
stemsee (in part) wrote:
Simple script to test connection without resorting to ping.
Thank you, stemsee!

Sheldon
Sheldon, You're welcome!
Back to top
View user's profile Send private message MSN Messenger 
stemsee

Joined: 27 Jun 2013
Posts: 2277
Location: In The Way

PostPosted: Wed 24 Jan 2018, 04:29    Post subject:  

Improvement
Code:
#!/bin/sh
# Test for network conection without ping
# adapted from https://bbs.archlinux.org/viewtopic.php?id=55485
#
j=0
for interface in $(ls /sys/class/net/ | grep -v lo);
do
   if [[ $(cat /sys/class/net/$interface/carrier) = 1 ]]; then
      OnLine="$interface is Online"
   elif [[  $(cat /sys/class/net/$interface/carrier) = 0 ]]; then
      OnLine="$interface is Not Online"
   fi
echo "$OnLine"
yad --text="$OnLine" --timeout=1 &
done
Back to top
View user's profile Send private message MSN Messenger 
stemsee

Joined: 27 Jun 2013
Posts: 2277
Location: In The Way

PostPosted: Sat 03 Feb 2018, 12:34    Post subject:  

So again updateing as really this only shows a connection to a network but not necessarily to the wan/internet

Code:

for inter in $(ls /sys/class/net/ | grep -v -e 'lo');
do
gotip=`ifconfig $inter | grep 'inet addr' | awk '{print $2}' | cut -f2 -d':'`
   if [[ $(cat /sys/class/net/$inter/carrier) = 1 ]]; then
      if [[ ! -z "$gotip" ]]; then
         OnLine="Connected with $gotip"
      else
         OnLine="$inter is Not Connected"
      fi
   elif [[  $(cat /sys/class/net/$inter/carrier) = 0 ]]; then
      if [[ -z "$gotip" ]]; then
         OnLine="$inter is Not Connected"
      else
         OnLine="Connected with $gotip"
      fi
   fi
echo "$OnLine"
yad --window-icon=/usr/share/pixmaps/wifi.png --title="$inter" \
--text="$OnLine" --no-buttons --skip-taskbar --timeout=2 &
done
curl ifconfig.me > /tmp/exip
yad --window-icon=/usr/share/pixmaps/wifi.png --title="$inter" \
--text="External ip `cat /tmp/exip` on internet" --no-buttons --skip-taskbar --timeout=2 &
Back to top
View user's profile Send private message MSN Messenger 
spiritwild


Joined: 03 Oct 2016
Posts: 160

PostPosted: Sat 03 Feb 2018, 16:52    Post subject:  

Thanks, cut the YAD part and added to my conky
Back to top
View user's profile Send private message 
musher0

Joined: 04 Jan 2009
Posts: 13187
Location: Gatineau (Qc), Canada

PostPosted: Sat 03 Feb 2018, 18:26    Post subject:  

Hi stemsee.

Great find! Great idea! We needed something like this.

May I suggest that you cut to the bone:
Code:
[ "`cat /sys/class/net/eth0/carrier`" -eq "1" ] && Status="On line" || Status="Off line"
echo "$Status"
Some convolutions you do not need, e.g. "export". And I'm assuming that "carrier"
has only two data positions: 0 or 1.

After that it's ok to use yad, bcm, or whatever, or even stay in the console Wink (yippee!)
to show the status.

BFN.

_________________
musher0
~~~~~~~~~~
Je suis né pour aimer et non pas pour haïr. (Sophocle) /
I was born to love and not to hate. (Sophocles)
Back to top
View user's profile Send private message 
stemsee

Joined: 27 Jun 2013
Posts: 2277
Location: In The Way

PostPosted: Sat 03 Feb 2018, 19:52    Post subject:  

Hi musher0

When the network interface cuts off uncleanly, be it eth0 or wlan0, (in my case eth0 wlan1 wlan4 usb0) carrier may still be set as '1' (yes '0' or '1') so the script would say wlan0 is online, when it is not. That is why I added the gotip check ... two tests to be certain. The curl ifconfig.me gets the external ip address thus proving evidence of connection also to the wide area network, not only the local area network.
the format is due to this being a function in my TrayNet app.

adjust your code to include these options and I will accept it.

cheers
stemsee
Back to top
View user's profile Send private message MSN Messenger 
musher0

Joined: 04 Jan 2009
Posts: 13187
Location: Gatineau (Qc), Canada

PostPosted: Sat 03 Feb 2018, 20:59    Post subject:  

Hi stemsee.

Euh... it's your code, you do as you wish. It was just a suggestion.

BTW, anything wrong with using
Code:
lsof -i | grep dhcpcd
Would it be reliable, you think?

BFN.

_________________
musher0
~~~~~~~~~~
Je suis né pour aimer et non pas pour haïr. (Sophocle) /
I was born to love and not to hate. (Sophocles)
Back to top
View user's profile Send private message 
stemsee

Joined: 27 Jun 2013
Posts: 2277
Location: In The Way

PostPosted: Sun 04 Feb 2018, 17:17    Post subject:  

Hi musher0

My network scripts connect with udhcpc and/or dhcpcd. There is a return on dhcpcd 'IPv4'; but nothing for udhcpc!

stemsee
Back to top
View user's profile Send private message MSN Messenger 
gyro

Joined: 28 Oct 2008
Posts: 1558
Location: Brisbane, Australia

PostPosted: Sun 04 Feb 2018, 18:36    Post subject:  

I don't get it:
Code:
curl ifconfig.me
is a connection to a web server.
Why is this better than a ping?
gyro
Back to top
View user's profile Send private message 
stemsee

Joined: 27 Jun 2013
Posts: 2277
Location: In The Way

PostPosted: Mon 05 Feb 2018, 08:57    Post subject:  

retracted
Last edited by stemsee on Mon 05 Feb 2018, 10:02; edited 1 time in total
Back to top
View user's profile Send private message MSN Messenger 
stemsee

Joined: 27 Jun 2013
Posts: 2277
Location: In The Way

PostPosted: Mon 05 Feb 2018, 10:02    Post subject:  

Hi @Gyro

No difference I guess. And 'curl ifconfig.me' is really slow!
Back to top
View user's profile Send private message MSN Messenger 
stemsee

Joined: 27 Jun 2013
Posts: 2277
Location: In The Way

PostPosted: Tue 20 Feb 2018, 20:21    Post subject:  

checking ability to post
Back to top
View user's profile Send private message MSN Messenger 
Display posts from previous:   Sort by:   
Page 1 of 1 [14 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Advanced Topics » Additional Software (PETs, n' stuff) » Network
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0479s ][ Queries: 14 (0.0090s) ][ GZIP on ]