-2

I have a project that requires me to scan the local network.

I found a program on the internet that allows the local network scanner condition, but I brought the gold @ IP argument in my network program must be turned the machine alone after two minutes.

So I determined a program from my PC IP and mask can give me the class CIDR (192.168.1.123/24), but to find this result I have to give the name of the network interface that my pc is connected (ie: wlan0, eth0 or eth1) to.

Q: Is there a method to find the name of the interface without the whole list as ifconfig does?

closed as unclear what you're asking by Anthon, Stephen Kitt, jasonwryan, Michael Homer, slm Mar 6 '15 at 0:27

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • How about route? Just grab the default and that will tell you. At least I think you're asking what is the default interface.. – SailorCire Mar 5 '15 at 15:01
  • 1
    Could you explain why you don't want to use ifconfig? That is the right tool for the job. – terdon Mar 5 '15 at 15:10
  • @terdon see the original question...it's an assignment that's why ifconfig can't be used. I just don't know if the user wants a list of all of the interfaces or just the default route interface. As we know, eth1 can exist even if it is the only card on the system, if there are 100 cards, or the default route and that's why I flagged it. I think you've cleared it up though. – SailorCire Mar 5 '15 at 15:16
  • 2
    @kaio, please stop adding explanations in comments. You need to explain exactly what you need in the body of your question. Please edit and explain exactly what you need and what limitations you have. – terdon Mar 5 '15 at 16:00
  • 1
    As I said, don't add stuff in comments, edit your question instead. Comments can be deleted without warning and are hard to read and easy to miss. Explain why you can't use ifconfig, explain what else you need (you mentioned scanning and netmask). – terdon Mar 5 '15 at 16:10
2

Get the default route, and catch the interface column:

nicolas@host:~$ ip route list | grep default | awk '{print $5} '
wlan0
  • awk '/default/ {print $5}' <(ip route) – jasonwryan Mar 5 '15 at 16:20
  • We need to go deeper: awk '/def/ {print $5}' <(ip r) :). My answer had a more explanatory approach, using long parameters. – user34720 Mar 5 '15 at 16:32
  • 3
    I was pointing out that using grep with awk is redundant and an unnecessary process... – jasonwryan Mar 5 '15 at 17:23
  • GNU grep can do the whole thing: ip r | grep -oP '^def.*\Keth.' – terdon Mar 5 '15 at 17:59
1

List the content of the directory /sys/class/net/. Each file in there corresponds to one interface. According to your question, you should find at least one file starting with eth.

  • thanks user236012 for your answer but when i open this file I find the three interfaces eth0 and waln0 l0 gold I am connected via wifi so that interests me is wlan0 in this case and in other cases I can find in this file and eth0 eth1 or so I am connected via eth1 my problem how can I recovered that which I am connected interface . – kaio Mar 5 '15 at 15:33
  • Punctuation saves lives – user236012 Mar 5 '15 at 15:43
  • Yes, but if I find eth1 and eth0 how I can learn from both the interface with which the PC is connected – kaio Mar 5 '15 at 15:50
  • In first place, you just wanted to know what the name of the wired interface was. Didn't read your edit, sorry! – user236012 Mar 5 '15 at 15:58

Not the answer you're looking for? Browse other questions tagged or ask your own question.