Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 11
Sorry for this stupid question. How to know if the Lan cable is plugged in ethernet card or not. If it possible I want to know how to check it ...
  1. #1
    Just Joined! garry_3peace's Avatar
    Join Date
    Oct 2008
    Posts
    67

    [SOLVED] Detect Lan cable plug/unplug

    Sorry for this stupid question. How to know if the Lan cable is plugged in ethernet card or not. If it possible I want to know how to check it at terminal and graphic mode.

    If I am not mistaken, to detect cable, we can use ping right? But what the error message do I get when it is unplugged. And also to where should I ping?

  2. #2
    Linux Engineer GNU-Fan's Avatar
    Join Date
    Mar 2008
    Posts
    935
    Hello,

    I do not know how to do this. But on my computer, if I pull the ethernet cable, a balloon notice comes up to tell me about what has happened. The program that does it is GNOME's network monitor applet.

    You can find it here
    https://launchpad.net/gnome-netstatus/

    to look how they did it.
    Debian GNU/Linux -- You know you want it.

  3. #3
    Just Joined! garry_3peace's Avatar
    Join Date
    Oct 2008
    Posts
    67
    Thanks GNU-Fan...
    I will take a look. But I still hope somebody can tell me how to see it, when in terminal...

  4. #4
    Linux Guru jmadero's Avatar
    Join Date
    Jul 2007
    Location
    California
    Posts
    1,958
    type ifconfig in terminal, you should see a bunch of stuff, if you are given an ip under eth0 or something like that, it's connected, if it doesn't, you're not
    Bodhi 1.3 & Bodhi 1.4 using E17
    Dell Studio 17, Intel Graphics card, 4 gigs of RAM, E17

    "The beauty in life can only be found by moving past the materialism which defines human nature and into the higher realm of thought and knowledge"

  5. #5
    Just Joined! garry_3peace's Avatar
    Join Date
    Oct 2008
    Posts
    67
    Hm... I've tried it. But no... The result of my ifconfig result when the cable unplugged is same with plugged.

  6. #6
    Linux Engineer khafa's Avatar
    Join Date
    Apr 2008
    Location
    Tokyo, Japan
    Posts
    858
    from the command line run the following command
    Code:
    nm-tool | -m 1 -i state
    if its connected it will return connected if not it will return disconnected.
    NOTE - this supposes that you are using NetworkManager(very likely)
    Linux and me it's a love story

  7. #7
    Linux Guru jmadero's Avatar
    Join Date
    Jul 2007
    Location
    California
    Posts
    1,958
    that doesn't make any sense (the ifconfig one). When you are plugged in you'll get an ip address for eth0....it'll be something like 192.168.1.X or something like that (depends on your routher/modem). When you are unplugged you won't get an ip for eth0 at all and it'll just be 000.000.0.0
    Bodhi 1.3 & Bodhi 1.4 using E17
    Dell Studio 17, Intel Graphics card, 4 gigs of RAM, E17

    "The beauty in life can only be found by moving past the materialism which defines human nature and into the higher realm of thought and knowledge"

  8. #8
    Linux Engineer khafa's Avatar
    Join Date
    Apr 2008
    Location
    Tokyo, Japan
    Posts
    858
    sorry , in my upper post i forgot the grep command. its as follows]
    Code:
    nm-tool | grep -m 1 -i state
    Quote Originally Posted by jmadero View Post
    that doesn't make any sense (the ifconfig one). When you are plugged in you'll get an ip address for eth0....it'll be something like 192.168.1.X or something like that (depends on your routher/modem). When you are unplugged you won't get an ip for eth0 at all and it'll just be 000.000.0.0
    this is when the cable is disconnected before the NIC gets its IP address but if after the NIC is configured and got its IP address if you unplug the cable ifconfig won't tell you about the state. i think that is what the thread owner is talking about. in that scenario what he said is correct as far as i know
    Linux and me it's a love story

  9. #9
    Just Joined! garry_3peace's Avatar
    Join Date
    Oct 2008
    Posts
    67

    Talking

    Yay.... thanks Khafa...
    I think this one is sufficient for me to detect the cable...
    btw, about the ifconfig problem, could it because I am using static IP, so I won't affect even I am disconnected?

  10. #10
    Linux Engineer khafa's Avatar
    Join Date
    Apr 2008
    Location
    Tokyo, Japan
    Posts
    858
    you can sum up like this
    1) NetworkManager:
    when you use NetworkManager(meaning that you let it control your connection) it will detect that the cable is unplugged and it will trigger a state change using the dbus messaging system. so in this case ifconfig is sufficient to know if the cable is plugged or not.

    2) without NetworkManager:
    in this case there is nothing to trigger the state change so ifconfig wont know about it and you need nm-tool to check the state as i gave you.
    Linux and me it's a love story

Page 1 of 2 1 2 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...