 |
 |
 |
 |
| Hardware & Laptops Help with your hardware, including laptop issues |

7th November 2012, 12:58 AM
|
 |
"Shells" (of a sub world)
|
|
Join Date: May 2011
Location: Helvetic Federation (Swissh)
Age: 33
Posts: 2,608

|
|
|
Is internet cable pluged in?
Heyas
Is there a file to check if a ethernet cable is pluged in to the laptop?
I did some search in /proc, but probably have missed the proper file, didnt recognize or mis interpreted that specific value.
Thank you
PS:
Ok, got some guesses:
* ip addr | grep BROADCAST | grep -v NO-CARRIER
* cat /sys/class/net/${em0|eth0|p3p1}/carrier
But i'm kinda unsure how accurate this is.
__________________
Fedora Manual: http://docs.fedoraproject.org
Script-Tools: https://sourceforge.net/projects/script-tools/
sudo st tweak repo toggle fedora-rawhide ; st iso dl-fed -respin && st iso usb
Last edited by sea; 7th November 2012 at 12:59 AM.
Reason: @Moderator: Please move to "Networking"
|

7th November 2012, 02:08 AM
|
 |
Registered User
|
|
Join Date: Apr 2006
Location: Ohio, USA
Posts: 8,302

|
|
|
Re: Is internet cable pluged in?
Quote:
[stevea@crucibulum Desktop]$ ip link show dev em1
3: em1: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN mode DEFAULT qlen 1000
link/ether f0:de:f1:22:46:c9 brd ff:ff:ff:ff:ff:ff
|
my post was too short
---------- Post added at 10:08 PM ---------- Previous post was at 10:02 PM ----------
Technically there is no way to test for connector plugged in except manually.
"NO-CARRIER" specifically means the interface is not connected to a to a LIVE connection.
A normal wired 100Mbit enet (for example) should be receiving a constant 125Mbit/sec stream with 5 bit IDLE symbols. The link reports NO-CARRIER when the IDLE (or other data) symbols are absent.
__________________
None are more hopelessly enslaved than those who falsely believe they are free.
Johann Wolfgang von Goethe
|

7th November 2012, 02:17 AM
|
 |
"Shells" (of a sub world)
|
|
Join Date: May 2011
Location: Helvetic Federation (Swissh)
Age: 33
Posts: 2,608

|
|
|
Re: Is internet cable pluged in?
By LIVE connection, you're talking about an extablished connection?
The coolest i've found so far is:
Code:
# by Brian Hunt
ip link | grep BROADCAST |cut -d ':' -f 2 | while read i; do echo $i; ethtool $i | grep Link ; done
That outputs that link on wlan0 is yes... it looks so close but yet it is the wrong one.
Is that like the carrier, LIVE thing, it just shows that it has no connection established yet?
__________________
Fedora Manual: http://docs.fedoraproject.org
Script-Tools: https://sourceforge.net/projects/script-tools/
sudo st tweak repo toggle fedora-rawhide ; st iso dl-fed -respin && st iso usb
|

7th November 2012, 02:41 AM
|
 |
Registered User
|
|
Join Date: Jun 2004
Location: Laurel, MD USA
Posts: 5,449

|
|
|
Re: Is internet cable pluged in?
Another way to confirm the cable is plugged in and the port is seeing the link is to use 'ethtool'
for example if your port is p4p1. The value to look for is:
|

7th November 2012, 03:57 AM
|
 |
Registered User
|
|
Join Date: Apr 2006
Location: Ohio, USA
Posts: 8,302

|
|
|
Re: Is internet cable pluged in?
Quote:
Originally Posted by sea
By LIVE connection, you're talking about an extablished connection?
|
In the case of wired - NO! It means your interface does/does-not see a live interface on the other end of the phy. "No Carrier "and "No Link" mean the same. The meaning is similar to picking up a wired phone and hearing/not-hearing a dial tone. Your term "established connection" implies some sort of connection oriented protocol of data passing both ways. Thats not the case. You can have CAQRIER (same as LINK UP) before he inteface is configured to communicate. It just means he hardware heards he "dial tone" generated from the far end of the wire. No information is passed aside from the one bit "the input wire is connected to incoming signal stream".
The meaning for wifi is a little different where "NO-CARRIER" seems to mean not associated with a WAP. Not sure for ad-hoc mode.
There is one more state that ethtool doesn't display well. If the interface is down then it cannot detect the 'dial tone' incoming signal. It's analogous to ...
/pickup phone, no dial tone: LINK DOWN
/pickup phone, had dial tone: LINK UP
/didn't pickup phone, ???: INTERFACE DOWN
Quote:
The coolest i've found so far is:
Code:
# by Brian Hunt
ip link | grep BROADCAST |cut -d ':' -f 2 | while read i; do echo $i; ethtool $i | grep Link ; done
That outputs that link on wlan0 is yes... it looks so close but yet it is the wrong one.
Is that like the carrier, LIVE thing, it just shows that it has no connection established yet?
|
I think that script is very UNcool.
a/ All the info is available from "ip link" but Mr.Hunt throws it away to get an interface list.
b/ Then the code iteratively calls "ethtool" to get the same info he threw away.
c/ ethtool generates an error msg for non-root users making it very annoying.
d/ It's silly to use pipe"|" read instead of "for i in $(...); do ...;done"
e/ grep BROADCAST is not a good way to select the desired interfaces. We could turn off BROADCAST and hide. He should de-select loopback.
Its a very poor script IMO. This one below is a bit better not ideal.
Code:
#!/bin/bash
for l in $(ip link | grep -v LOOPBACK | grep "^[0-9]" | cut -d' ' -f2-3 | tr -d ' ')
do
echo -en "$(echo $l|cut -d\< -f1)\t"
echo $l|grep -q "[<,]UP[,>]" \
&& (echo $l|grep -q "[<,]NO-CARRIER[,>]" && echo "LINK DOWN" || echo "LINK UP" ) \
|| echo "INTERFACE DOWN"
done
Code:
[stevea@crucibulum Desktop]$ ./foo
wlan0: LINK UP
em1: INTERFACE DOWN
virbr0: LINK DOWN
[stevea@crucibulum Desktop]$ ip link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN mode DEFAULT
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DORMANT qlen 1000
link/ether 00:24:d7:63:42:68 brd ff:ff:ff:ff:ff:ff
3: em1: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast state DOWN mode DEFAULT qlen 1000
link/ether f0:de:f1:22:46:c9 brd ff:ff:ff:ff:ff:ff
4: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN mode DEFAULT
link/ether 4a:dd:50:30:e8:0d brd ff:ff:ff:ff:ff:ff
__________________
None are more hopelessly enslaved than those who falsely believe they are free.
Johann Wolfgang von Goethe
Last edited by stevea; 7th November 2012 at 06:56 AM.
|

7th November 2012, 11:57 AM
|
 |
"Shells" (of a sub world)
|
|
Join Date: May 2011
Location: Helvetic Federation (Swissh)
Age: 33
Posts: 2,608

|
|
|
Re: Is internet cable pluged in?
@ Marko, no the ethtool wlan0 shows up Link: yes, but the wlan has no wire, so this value shows if a connection has been made, but not the availablity of a wire.
@ Stevea, seems you're using wlan0 too
Quote:
Originally Posted by stevea
You can have CAQRIER (same as LINK UP) before he inteface is configured to communicate. It just means he hardware heards he "dial tone" generated from the far end of the wire. No information is passed aside from the one bit "the input wire is connected to incoming signal stream".
|
So the LinkUp / Carrier=1 (cat /sys/class/net/${em0|eth0|p3p1}/carrier) is the key to the 'dial tone' which i could interpret as wire pluged in if its not the wifi device?
But then again, thats about the same info as ethtool em0|grep Link
Another confirmation that networking is not by best skill
__________________
Fedora Manual: http://docs.fedoraproject.org
Script-Tools: https://sourceforge.net/projects/script-tools/
sudo st tweak repo toggle fedora-rawhide ; st iso dl-fed -respin && st iso usb
|

8th November 2012, 12:04 AM
|
 |
"Shells" (of a sub world)
|
|
Join Date: May 2011
Location: Helvetic Federation (Swissh)
Age: 33
Posts: 2,608

|
|
|
Re: Is internet cable pluged in?
As most of my posts end up as a script, here's the reason for this one:
I tried to write up a script, that, once the settings are configured the first time, could be run in background.
In the minimalistic approach to my systems, i'd like to get rid of NetworManager, so i wrote my own
It seems to be working on my 2 machines, and i hope it does on others too.
/*
EDIT:
Sadly i was "testing" when NetworkManager did establish a connection,
since the script seemed to work, i was too eager to share it.
*/
This is as of now, and since my questions were answered this thread is solved.
If the script gets updated, you'll find it at: http://sea.hostingsociety.com/?p=Scripts&stc=sea-nm
__________________
Fedora Manual: http://docs.fedoraproject.org
Script-Tools: https://sourceforge.net/projects/script-tools/
sudo st tweak repo toggle fedora-rawhide ; st iso dl-fed -respin && st iso usb
Last edited by sea; 8th November 2012 at 01:48 AM.
|

8th November 2012, 12:11 AM
|
 |
Registered User
|
|
Join Date: Jun 2004
Location: Laurel, MD USA
Posts: 5,449

|
|
|
Re: Is internet cable pluged in?
Quote:
Originally Posted by sea
@ Marko, no the ethtool wlan0 shows up Link: yes, but the wlan has no wire, so this value shows if a connection has been made, but not the availablity of a wire.
|
Not sure what you're talking about there, in my post #4 I was talking about using ethtool against a wired port and not wlan0 which is wireless.
But note even there it can't just detect a wire is plugged in, it might be that the other end is dangling and not plugged into anything. For wired ethernet, you'd get "link detected" if the other end is in a live port (I think it just detects there voltage), the remote port doesn't have to be UP
|

8th November 2012, 12:15 AM
|
 |
"Shells" (of a sub world)
|
|
Join Date: May 2011
Location: Helvetic Federation (Swissh)
Age: 33
Posts: 2,608

|
|
|
Re: Is internet cable pluged in?
Oh, i see.
Thank you Marko
__________________
Fedora Manual: http://docs.fedoraproject.org
Script-Tools: https://sourceforge.net/projects/script-tools/
sudo st tweak repo toggle fedora-rawhide ; st iso dl-fed -respin && st iso usb
|

8th November 2012, 12:27 AM
|
 |
Registered User
|
|
Join Date: Apr 2006
Location: Ohio, USA
Posts: 8,302

|
|
|
Re: Is internet cable pluged in?
Quote:
Originally Posted by sea
So the LinkUp / Carrier=1 (cat /sys/class/net/${em0|eth0|p3p1}/carrier) is the key to the 'dial tone' which i could interpret as wire pluged in if its not the wifi device?
But then again, thats about the same info as ethtool em0|grep Link 
|
Right - they are basically the same info with two exception.
ethtool throws an error when an unprivileged user uses it.
Quote:
|
Cannot get wake-on-lan settings: Operation not permitted
|
which is IMO a stupid error within ethtool.
Also ethtool just reports "Link detected: no" even when the interface is down.
This is similar to saying "there was no dial-tone detected" when you didn't bother to pick up the handset and listen.
I think the /sys/class/net/ has a lot of advantages tho' the content of /sys is not terribly stable as the kernel changes.
__________________
None are more hopelessly enslaved than those who falsely believe they are free.
Johann Wolfgang von Goethe
|

8th November 2012, 01:12 AM
|
 |
Registered User
|
|
Join Date: Jun 2004
Location: Laurel, MD USA
Posts: 5,449

|
|
|
Re: Is internet cable pluged in?
Quote:
Originally Posted by sea
Oh, i see.
Thank you Marko
|
ethtool has another feature that's very handy, you can get it to blink the LEDs on a particular port:
for example, would blink the leds on the "em0' wired port. I guess what it would do on a wireless port is undefined or it might blink the activity light if you had one on the front of the case for the wireless.
|

8th November 2012, 01:18 AM
|
 |
"Shells" (of a sub world)
|
|
Join Date: May 2011
Location: Helvetic Federation (Swissh)
Age: 33
Posts: 2,608

|
|
|
Re: Is internet cable pluged in?
Added:
Code:
isWired() { #
# Checks internetdevices not starting with "w"
# if they are probably pluged in.
for dev in $(list_device_internet nolo)
do [ ! "w" = "${dev:0:1}" ] && \
isPluged $dev && \
return 0
done
return 1
}
list_device_internet() { # [ nolo ]
# Returns an array of available internet devices
#
list_all=""
veryraw=$(cat /proc/net/dev|grep ":"|awk '{print $1}')
for r in $veryraw;do list_all="$list_all ${r:0:(-1)}";done
if [ "nolo" = "$1" ]
then for o in $list_all
do test ! "$o" = "lo" && \
printf " $o "
done
else for o in $list_all
do printf " $o "
done
fi
}
isRedhatbased() { #
# Simply checks if file /etc/redhat-release is not empty
# Returns 0 for CentOS, Fedora, RedHat, Scientific Linux, 1 otherwise
retval=1
test ! "" = $(cat /etc/redhat-release) && retval=0
return $retval
}
Changed:
Code:
isPluged() { # DEVICE
# Best guess to get a chance if the wire is pluged in.
# BETA
[ "" = "$1" ] && sE "Usage: isPluged p3p1" "$FAILURE" && return 1
respond=$(cat /sys/class/net/$1/carrier) > /dev/zero || return 1
#respond=$(ethtool $1|grep Link|awk '{print $3}')
[ "1" = "$respond" ] && retval=0 || retval=1
[ 0 -eq $retval ] && \
sE "$1 is probably wired" "$SUCCESS" || \
sE "Is there no wire?" "$FAILURE"
return $retval
}
__________________
Fedora Manual: http://docs.fedoraproject.org
Script-Tools: https://sourceforge.net/projects/script-tools/
sudo st tweak repo toggle fedora-rawhide ; st iso dl-fed -respin && st iso usb
Last edited by sea; 8th November 2012 at 01:24 AM.
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
Current GMT-time: 15:49 (Friday, 24-05-2013)
|
|
 |
 |
 |
 |
|
|