How to use ifconfig to show active interface only

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
14
down vote

favorite
9












By default ifconfig will show me all available interfaces , but what if I just want to display active ones? Like, en0 only in below.



en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
ether 14:10:9f:e0:eb:c9
inet6 fe80::1610:9fff:fee0:ebc9%en0 prefixlen 64 scopeid 0x4
inet X.X.X.X netmask 0xffffff00 broadcast 101.6.69.255
nd6 options=1<PERFORMNUD>
media: autoselect
**status: active**
en3: flags=8963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500
options=60<TSO4,TSO6>
ether 32:00:14:e7:4f:80
media: autoselect <full-duplex>
**status: inactive**


Notice ifconfig en0 will not satisfy, en0 is not always the active one ;)



I'm running Mac OS X.










share|improve this question



















  • 2




    Your OS would be something important to mention since ifconfig implementations vary. Also, why is the use ifconfig a requirement? What is your end goal?
    – jordanm
    Dec 1 '13 at 6:01










  • Hi @jordanm, my goal is to to get IP address of currently active interface, often a wireless or wired Ethernet interface.
    – qweruiop
    Dec 1 '13 at 6:18














up vote
14
down vote

favorite
9












By default ifconfig will show me all available interfaces , but what if I just want to display active ones? Like, en0 only in below.



en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
ether 14:10:9f:e0:eb:c9
inet6 fe80::1610:9fff:fee0:ebc9%en0 prefixlen 64 scopeid 0x4
inet X.X.X.X netmask 0xffffff00 broadcast 101.6.69.255
nd6 options=1<PERFORMNUD>
media: autoselect
**status: active**
en3: flags=8963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500
options=60<TSO4,TSO6>
ether 32:00:14:e7:4f:80
media: autoselect <full-duplex>
**status: inactive**


Notice ifconfig en0 will not satisfy, en0 is not always the active one ;)



I'm running Mac OS X.










share|improve this question



















  • 2




    Your OS would be something important to mention since ifconfig implementations vary. Also, why is the use ifconfig a requirement? What is your end goal?
    – jordanm
    Dec 1 '13 at 6:01










  • Hi @jordanm, my goal is to to get IP address of currently active interface, often a wireless or wired Ethernet interface.
    – qweruiop
    Dec 1 '13 at 6:18












up vote
14
down vote

favorite
9









up vote
14
down vote

favorite
9






9





By default ifconfig will show me all available interfaces , but what if I just want to display active ones? Like, en0 only in below.



en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
ether 14:10:9f:e0:eb:c9
inet6 fe80::1610:9fff:fee0:ebc9%en0 prefixlen 64 scopeid 0x4
inet X.X.X.X netmask 0xffffff00 broadcast 101.6.69.255
nd6 options=1<PERFORMNUD>
media: autoselect
**status: active**
en3: flags=8963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500
options=60<TSO4,TSO6>
ether 32:00:14:e7:4f:80
media: autoselect <full-duplex>
**status: inactive**


Notice ifconfig en0 will not satisfy, en0 is not always the active one ;)



I'm running Mac OS X.










share|improve this question















By default ifconfig will show me all available interfaces , but what if I just want to display active ones? Like, en0 only in below.



en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
ether 14:10:9f:e0:eb:c9
inet6 fe80::1610:9fff:fee0:ebc9%en0 prefixlen 64 scopeid 0x4
inet X.X.X.X netmask 0xffffff00 broadcast 101.6.69.255
nd6 options=1<PERFORMNUD>
media: autoselect
**status: active**
en3: flags=8963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500
options=60<TSO4,TSO6>
ether 32:00:14:e7:4f:80
media: autoselect <full-duplex>
**status: inactive**


Notice ifconfig en0 will not satisfy, en0 is not always the active one ;)



I'm running Mac OS X.







command-line networking osx interface






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 1 '13 at 8:25









Mat

37.9k7114123




37.9k7114123










asked Dec 1 '13 at 5:15









qweruiop

210128




210128







  • 2




    Your OS would be something important to mention since ifconfig implementations vary. Also, why is the use ifconfig a requirement? What is your end goal?
    – jordanm
    Dec 1 '13 at 6:01










  • Hi @jordanm, my goal is to to get IP address of currently active interface, often a wireless or wired Ethernet interface.
    – qweruiop
    Dec 1 '13 at 6:18












  • 2




    Your OS would be something important to mention since ifconfig implementations vary. Also, why is the use ifconfig a requirement? What is your end goal?
    – jordanm
    Dec 1 '13 at 6:01










  • Hi @jordanm, my goal is to to get IP address of currently active interface, often a wireless or wired Ethernet interface.
    – qweruiop
    Dec 1 '13 at 6:18







2




2




Your OS would be something important to mention since ifconfig implementations vary. Also, why is the use ifconfig a requirement? What is your end goal?
– jordanm
Dec 1 '13 at 6:01




Your OS would be something important to mention since ifconfig implementations vary. Also, why is the use ifconfig a requirement? What is your end goal?
– jordanm
Dec 1 '13 at 6:01












Hi @jordanm, my goal is to to get IP address of currently active interface, often a wireless or wired Ethernet interface.
– qweruiop
Dec 1 '13 at 6:18




Hi @jordanm, my goal is to to get IP address of currently active interface, often a wireless or wired Ethernet interface.
– qweruiop
Dec 1 '13 at 6:18










7 Answers
7






active

oldest

votes

















up vote
20
down vote



accepted










To get a complete description of all the active services, try:



ifconfig | pcregrep -M -o '^[^t:]+:([^n]|nt)*status: active'


This simple regex should filter out only active interfaces and all their information. I sugest you put an alias for this in your ~/.profile or ~/.bash_profile file (maybe ifconfiga?)



To just get the interface name (useful for scripts), use:



ifconfig | pcregrep -M -o '^[^t:]+:([^n]|nt)*status: active' | egrep -o -m 1 '^[^t:]+'


You have to install pcregrep for this to work. It's on macports in the pcre package. Alternatively, this should work with GNU grep using grep -Pzo instead of pcregrep -M -o but with the rest the same, but I haven't tested this.






share|improve this answer





























    up vote
    3
    down vote













    If you only want to print the “entry” if it contains status: active, then you could use something like this awk program as a filter to the ifconfig output:



    #!/usr/bin/awk -f
    BEGIN print_it = 0
    /status: active/ print_it = 1
    /^($|[^t])/ if(print_it) print buffer; buffer = $0; print_it = 0
    /^t/ buffer = buffer "n" $0
    END if(print_it) print buffer


    When each “entry” starts (a line is empty or does not start with a Tab), start saving the entry in a buffer. Append to this buffer any subsequent lines that start with a Tab. Watch for the magic string status: active; if a line like that was seen, print out the buffer (the previous “entry”) when a new “entry” starts (or the input ends).



    Save the above program text in a file and use it like this:



    ifconfig -a | awk -f /path/to/file


    Or, if you chmod +x the file, then you can simplify it a bit:



    ifconfig -a | /path/to/file





    share|improve this answer



























      up vote
      2
      down vote













      Reading your comments and question, it seems you actually want to just get the interfaces that have an IP address assigned to them.



      You can do this quickly with ifconfig and grep.



      Running the command:



      ifconfig | grep 'Link|inet'


      Should produce something similar to:




      eth0 Link encap:Ethernet HWaddr 00:11:22:33:44:55
      eth1 Link encap:Ethernet HWaddr 00:11:22:33:44:66
      inet addr:192.168.0.8 Bcast:192.168.0.255 Mask:255.255.255.0
      lo Link encap:Local Loopback
      inet addr:127.0.0.1 Mask:255.0.0.0


      This would show each line with a interface name and and IP if they had one.



      Some more specific REGEX magic might get you exactly what you need.






      share|improve this answer


















      • 2




        Thanks but where is active consideration ?
        – qweruiop
        Dec 1 '13 at 15:22










      • if there is a line after the interface, then it has an IP address assigned to it, and by what I gather you mean, it would constitute as 'active'.
        – Nathan McCoy
        Dec 27 '13 at 17:14

















      up vote
      0
      down vote













      Following will print out only those interfaces that are configured to have an IP



      ifconfig | grep "inet.*broadcast"





      share|improve this answer





























        up vote
        -1
        down vote













        If you are not adverse to some bash scripting, you can do this:



        for i in $(ifconfig -lu); do if ifconfig $i | grep -q "status: active" ; then echo $i; fi; done


        That's will list out the active network interfaces. Tested on Mac OS X 10.13.



        The nice thing is that you don't need to install anything. Just run the above in a Terminal.






        share|improve this answer





























          up vote
          -2
          down vote













          $ ifconfig | grep "inet addr:" | grep -v 127.0.0.1 | sed -e 's/Bcast//' | cut -d: -f2


          How it works:



          • ifconfig

          • Grep for lines containing "inet addr"

            • These lines contains the IPs.


          • Grep for lines that do not contain "127.0.0.1"

            • We usually do not care about localhost.

            • -v is inverted grep


          • From remaining lines, remove the "Bcast"

          • Cut field 2 using ":" as a delimiter

            • Prints the answer.






          share|improve this answer





























            up vote
            -2
            down vote













            ifconfig en0 | grep status


            This will show the status of the ethernet connection en0






            share|improve this answer






















              Your Answer







              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "106"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              convertImagesToLinks: false,
              noModals: false,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













               

              draft saved


              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f103241%2fhow-to-use-ifconfig-to-show-active-interface-only%23new-answer', 'question_page');

              );

              Post as a guest






























              7 Answers
              7






              active

              oldest

              votes








              7 Answers
              7






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              20
              down vote



              accepted










              To get a complete description of all the active services, try:



              ifconfig | pcregrep -M -o '^[^t:]+:([^n]|nt)*status: active'


              This simple regex should filter out only active interfaces and all their information. I sugest you put an alias for this in your ~/.profile or ~/.bash_profile file (maybe ifconfiga?)



              To just get the interface name (useful for scripts), use:



              ifconfig | pcregrep -M -o '^[^t:]+:([^n]|nt)*status: active' | egrep -o -m 1 '^[^t:]+'


              You have to install pcregrep for this to work. It's on macports in the pcre package. Alternatively, this should work with GNU grep using grep -Pzo instead of pcregrep -M -o but with the rest the same, but I haven't tested this.






              share|improve this answer


























                up vote
                20
                down vote



                accepted










                To get a complete description of all the active services, try:



                ifconfig | pcregrep -M -o '^[^t:]+:([^n]|nt)*status: active'


                This simple regex should filter out only active interfaces and all their information. I sugest you put an alias for this in your ~/.profile or ~/.bash_profile file (maybe ifconfiga?)



                To just get the interface name (useful for scripts), use:



                ifconfig | pcregrep -M -o '^[^t:]+:([^n]|nt)*status: active' | egrep -o -m 1 '^[^t:]+'


                You have to install pcregrep for this to work. It's on macports in the pcre package. Alternatively, this should work with GNU grep using grep -Pzo instead of pcregrep -M -o but with the rest the same, but I haven't tested this.






                share|improve this answer
























                  up vote
                  20
                  down vote



                  accepted







                  up vote
                  20
                  down vote



                  accepted






                  To get a complete description of all the active services, try:



                  ifconfig | pcregrep -M -o '^[^t:]+:([^n]|nt)*status: active'


                  This simple regex should filter out only active interfaces and all their information. I sugest you put an alias for this in your ~/.profile or ~/.bash_profile file (maybe ifconfiga?)



                  To just get the interface name (useful for scripts), use:



                  ifconfig | pcregrep -M -o '^[^t:]+:([^n]|nt)*status: active' | egrep -o -m 1 '^[^t:]+'


                  You have to install pcregrep for this to work. It's on macports in the pcre package. Alternatively, this should work with GNU grep using grep -Pzo instead of pcregrep -M -o but with the rest the same, but I haven't tested this.






                  share|improve this answer














                  To get a complete description of all the active services, try:



                  ifconfig | pcregrep -M -o '^[^t:]+:([^n]|nt)*status: active'


                  This simple regex should filter out only active interfaces and all their information. I sugest you put an alias for this in your ~/.profile or ~/.bash_profile file (maybe ifconfiga?)



                  To just get the interface name (useful for scripts), use:



                  ifconfig | pcregrep -M -o '^[^t:]+:([^n]|nt)*status: active' | egrep -o -m 1 '^[^t:]+'


                  You have to install pcregrep for this to work. It's on macports in the pcre package. Alternatively, this should work with GNU grep using grep -Pzo instead of pcregrep -M -o but with the rest the same, but I haven't tested this.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Sep 8 '14 at 5:53

























                  answered Jan 6 '14 at 10:22









                  g.rocket

                  354112




                  354112






















                      up vote
                      3
                      down vote













                      If you only want to print the “entry” if it contains status: active, then you could use something like this awk program as a filter to the ifconfig output:



                      #!/usr/bin/awk -f
                      BEGIN print_it = 0
                      /status: active/ print_it = 1
                      /^($|[^t])/ if(print_it) print buffer; buffer = $0; print_it = 0
                      /^t/ buffer = buffer "n" $0
                      END if(print_it) print buffer


                      When each “entry” starts (a line is empty or does not start with a Tab), start saving the entry in a buffer. Append to this buffer any subsequent lines that start with a Tab. Watch for the magic string status: active; if a line like that was seen, print out the buffer (the previous “entry”) when a new “entry” starts (or the input ends).



                      Save the above program text in a file and use it like this:



                      ifconfig -a | awk -f /path/to/file


                      Or, if you chmod +x the file, then you can simplify it a bit:



                      ifconfig -a | /path/to/file





                      share|improve this answer
























                        up vote
                        3
                        down vote













                        If you only want to print the “entry” if it contains status: active, then you could use something like this awk program as a filter to the ifconfig output:



                        #!/usr/bin/awk -f
                        BEGIN print_it = 0
                        /status: active/ print_it = 1
                        /^($|[^t])/ if(print_it) print buffer; buffer = $0; print_it = 0
                        /^t/ buffer = buffer "n" $0
                        END if(print_it) print buffer


                        When each “entry” starts (a line is empty or does not start with a Tab), start saving the entry in a buffer. Append to this buffer any subsequent lines that start with a Tab. Watch for the magic string status: active; if a line like that was seen, print out the buffer (the previous “entry”) when a new “entry” starts (or the input ends).



                        Save the above program text in a file and use it like this:



                        ifconfig -a | awk -f /path/to/file


                        Or, if you chmod +x the file, then you can simplify it a bit:



                        ifconfig -a | /path/to/file





                        share|improve this answer






















                          up vote
                          3
                          down vote










                          up vote
                          3
                          down vote









                          If you only want to print the “entry” if it contains status: active, then you could use something like this awk program as a filter to the ifconfig output:



                          #!/usr/bin/awk -f
                          BEGIN print_it = 0
                          /status: active/ print_it = 1
                          /^($|[^t])/ if(print_it) print buffer; buffer = $0; print_it = 0
                          /^t/ buffer = buffer "n" $0
                          END if(print_it) print buffer


                          When each “entry” starts (a line is empty or does not start with a Tab), start saving the entry in a buffer. Append to this buffer any subsequent lines that start with a Tab. Watch for the magic string status: active; if a line like that was seen, print out the buffer (the previous “entry”) when a new “entry” starts (or the input ends).



                          Save the above program text in a file and use it like this:



                          ifconfig -a | awk -f /path/to/file


                          Or, if you chmod +x the file, then you can simplify it a bit:



                          ifconfig -a | /path/to/file





                          share|improve this answer












                          If you only want to print the “entry” if it contains status: active, then you could use something like this awk program as a filter to the ifconfig output:



                          #!/usr/bin/awk -f
                          BEGIN print_it = 0
                          /status: active/ print_it = 1
                          /^($|[^t])/ if(print_it) print buffer; buffer = $0; print_it = 0
                          /^t/ buffer = buffer "n" $0
                          END if(print_it) print buffer


                          When each “entry” starts (a line is empty or does not start with a Tab), start saving the entry in a buffer. Append to this buffer any subsequent lines that start with a Tab. Watch for the magic string status: active; if a line like that was seen, print out the buffer (the previous “entry”) when a new “entry” starts (or the input ends).



                          Save the above program text in a file and use it like this:



                          ifconfig -a | awk -f /path/to/file


                          Or, if you chmod +x the file, then you can simplify it a bit:



                          ifconfig -a | /path/to/file






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Dec 3 '13 at 7:24









                          Chris Johnsen

                          14.3k64746




                          14.3k64746




















                              up vote
                              2
                              down vote













                              Reading your comments and question, it seems you actually want to just get the interfaces that have an IP address assigned to them.



                              You can do this quickly with ifconfig and grep.



                              Running the command:



                              ifconfig | grep 'Link|inet'


                              Should produce something similar to:




                              eth0 Link encap:Ethernet HWaddr 00:11:22:33:44:55
                              eth1 Link encap:Ethernet HWaddr 00:11:22:33:44:66
                              inet addr:192.168.0.8 Bcast:192.168.0.255 Mask:255.255.255.0
                              lo Link encap:Local Loopback
                              inet addr:127.0.0.1 Mask:255.0.0.0


                              This would show each line with a interface name and and IP if they had one.



                              Some more specific REGEX magic might get you exactly what you need.






                              share|improve this answer


















                              • 2




                                Thanks but where is active consideration ?
                                – qweruiop
                                Dec 1 '13 at 15:22










                              • if there is a line after the interface, then it has an IP address assigned to it, and by what I gather you mean, it would constitute as 'active'.
                                – Nathan McCoy
                                Dec 27 '13 at 17:14














                              up vote
                              2
                              down vote













                              Reading your comments and question, it seems you actually want to just get the interfaces that have an IP address assigned to them.



                              You can do this quickly with ifconfig and grep.



                              Running the command:



                              ifconfig | grep 'Link|inet'


                              Should produce something similar to:




                              eth0 Link encap:Ethernet HWaddr 00:11:22:33:44:55
                              eth1 Link encap:Ethernet HWaddr 00:11:22:33:44:66
                              inet addr:192.168.0.8 Bcast:192.168.0.255 Mask:255.255.255.0
                              lo Link encap:Local Loopback
                              inet addr:127.0.0.1 Mask:255.0.0.0


                              This would show each line with a interface name and and IP if they had one.



                              Some more specific REGEX magic might get you exactly what you need.






                              share|improve this answer


















                              • 2




                                Thanks but where is active consideration ?
                                – qweruiop
                                Dec 1 '13 at 15:22










                              • if there is a line after the interface, then it has an IP address assigned to it, and by what I gather you mean, it would constitute as 'active'.
                                – Nathan McCoy
                                Dec 27 '13 at 17:14












                              up vote
                              2
                              down vote










                              up vote
                              2
                              down vote









                              Reading your comments and question, it seems you actually want to just get the interfaces that have an IP address assigned to them.



                              You can do this quickly with ifconfig and grep.



                              Running the command:



                              ifconfig | grep 'Link|inet'


                              Should produce something similar to:




                              eth0 Link encap:Ethernet HWaddr 00:11:22:33:44:55
                              eth1 Link encap:Ethernet HWaddr 00:11:22:33:44:66
                              inet addr:192.168.0.8 Bcast:192.168.0.255 Mask:255.255.255.0
                              lo Link encap:Local Loopback
                              inet addr:127.0.0.1 Mask:255.0.0.0


                              This would show each line with a interface name and and IP if they had one.



                              Some more specific REGEX magic might get you exactly what you need.






                              share|improve this answer














                              Reading your comments and question, it seems you actually want to just get the interfaces that have an IP address assigned to them.



                              You can do this quickly with ifconfig and grep.



                              Running the command:



                              ifconfig | grep 'Link|inet'


                              Should produce something similar to:




                              eth0 Link encap:Ethernet HWaddr 00:11:22:33:44:55
                              eth1 Link encap:Ethernet HWaddr 00:11:22:33:44:66
                              inet addr:192.168.0.8 Bcast:192.168.0.255 Mask:255.255.255.0
                              lo Link encap:Local Loopback
                              inet addr:127.0.0.1 Mask:255.0.0.0


                              This would show each line with a interface name and and IP if they had one.



                              Some more specific REGEX magic might get you exactly what you need.







                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited Dec 1 '13 at 9:38

























                              answered Dec 1 '13 at 9:32









                              Nathan McCoy

                              554414




                              554414







                              • 2




                                Thanks but where is active consideration ?
                                – qweruiop
                                Dec 1 '13 at 15:22










                              • if there is a line after the interface, then it has an IP address assigned to it, and by what I gather you mean, it would constitute as 'active'.
                                – Nathan McCoy
                                Dec 27 '13 at 17:14












                              • 2




                                Thanks but where is active consideration ?
                                – qweruiop
                                Dec 1 '13 at 15:22










                              • if there is a line after the interface, then it has an IP address assigned to it, and by what I gather you mean, it would constitute as 'active'.
                                – Nathan McCoy
                                Dec 27 '13 at 17:14







                              2




                              2




                              Thanks but where is active consideration ?
                              – qweruiop
                              Dec 1 '13 at 15:22




                              Thanks but where is active consideration ?
                              – qweruiop
                              Dec 1 '13 at 15:22












                              if there is a line after the interface, then it has an IP address assigned to it, and by what I gather you mean, it would constitute as 'active'.
                              – Nathan McCoy
                              Dec 27 '13 at 17:14




                              if there is a line after the interface, then it has an IP address assigned to it, and by what I gather you mean, it would constitute as 'active'.
                              – Nathan McCoy
                              Dec 27 '13 at 17:14










                              up vote
                              0
                              down vote













                              Following will print out only those interfaces that are configured to have an IP



                              ifconfig | grep "inet.*broadcast"





                              share|improve this answer


























                                up vote
                                0
                                down vote













                                Following will print out only those interfaces that are configured to have an IP



                                ifconfig | grep "inet.*broadcast"





                                share|improve this answer
























                                  up vote
                                  0
                                  down vote










                                  up vote
                                  0
                                  down vote









                                  Following will print out only those interfaces that are configured to have an IP



                                  ifconfig | grep "inet.*broadcast"





                                  share|improve this answer














                                  Following will print out only those interfaces that are configured to have an IP



                                  ifconfig | grep "inet.*broadcast"






                                  share|improve this answer














                                  share|improve this answer



                                  share|improve this answer








                                  edited Nov 29 '16 at 16:44









                                  HalosGhost

                                  3,57592035




                                  3,57592035










                                  answered Nov 29 '16 at 16:27









                                  Yousif Atique

                                  1




                                  1




















                                      up vote
                                      -1
                                      down vote













                                      If you are not adverse to some bash scripting, you can do this:



                                      for i in $(ifconfig -lu); do if ifconfig $i | grep -q "status: active" ; then echo $i; fi; done


                                      That's will list out the active network interfaces. Tested on Mac OS X 10.13.



                                      The nice thing is that you don't need to install anything. Just run the above in a Terminal.






                                      share|improve this answer


























                                        up vote
                                        -1
                                        down vote













                                        If you are not adverse to some bash scripting, you can do this:



                                        for i in $(ifconfig -lu); do if ifconfig $i | grep -q "status: active" ; then echo $i; fi; done


                                        That's will list out the active network interfaces. Tested on Mac OS X 10.13.



                                        The nice thing is that you don't need to install anything. Just run the above in a Terminal.






                                        share|improve this answer
























                                          up vote
                                          -1
                                          down vote










                                          up vote
                                          -1
                                          down vote









                                          If you are not adverse to some bash scripting, you can do this:



                                          for i in $(ifconfig -lu); do if ifconfig $i | grep -q "status: active" ; then echo $i; fi; done


                                          That's will list out the active network interfaces. Tested on Mac OS X 10.13.



                                          The nice thing is that you don't need to install anything. Just run the above in a Terminal.






                                          share|improve this answer














                                          If you are not adverse to some bash scripting, you can do this:



                                          for i in $(ifconfig -lu); do if ifconfig $i | grep -q "status: active" ; then echo $i; fi; done


                                          That's will list out the active network interfaces. Tested on Mac OS X 10.13.



                                          The nice thing is that you don't need to install anything. Just run the above in a Terminal.







                                          share|improve this answer














                                          share|improve this answer



                                          share|improve this answer








                                          edited Sep 16 at 19:19









                                          Goro

                                          5,89552662




                                          5,89552662










                                          answered Sep 16 at 19:14









                                          Claudio

                                          1




                                          1




















                                              up vote
                                              -2
                                              down vote













                                              $ ifconfig | grep "inet addr:" | grep -v 127.0.0.1 | sed -e 's/Bcast//' | cut -d: -f2


                                              How it works:



                                              • ifconfig

                                              • Grep for lines containing "inet addr"

                                                • These lines contains the IPs.


                                              • Grep for lines that do not contain "127.0.0.1"

                                                • We usually do not care about localhost.

                                                • -v is inverted grep


                                              • From remaining lines, remove the "Bcast"

                                              • Cut field 2 using ":" as a delimiter

                                                • Prints the answer.






                                              share|improve this answer


























                                                up vote
                                                -2
                                                down vote













                                                $ ifconfig | grep "inet addr:" | grep -v 127.0.0.1 | sed -e 's/Bcast//' | cut -d: -f2


                                                How it works:



                                                • ifconfig

                                                • Grep for lines containing "inet addr"

                                                  • These lines contains the IPs.


                                                • Grep for lines that do not contain "127.0.0.1"

                                                  • We usually do not care about localhost.

                                                  • -v is inverted grep


                                                • From remaining lines, remove the "Bcast"

                                                • Cut field 2 using ":" as a delimiter

                                                  • Prints the answer.






                                                share|improve this answer
























                                                  up vote
                                                  -2
                                                  down vote










                                                  up vote
                                                  -2
                                                  down vote









                                                  $ ifconfig | grep "inet addr:" | grep -v 127.0.0.1 | sed -e 's/Bcast//' | cut -d: -f2


                                                  How it works:



                                                  • ifconfig

                                                  • Grep for lines containing "inet addr"

                                                    • These lines contains the IPs.


                                                  • Grep for lines that do not contain "127.0.0.1"

                                                    • We usually do not care about localhost.

                                                    • -v is inverted grep


                                                  • From remaining lines, remove the "Bcast"

                                                  • Cut field 2 using ":" as a delimiter

                                                    • Prints the answer.






                                                  share|improve this answer














                                                  $ ifconfig | grep "inet addr:" | grep -v 127.0.0.1 | sed -e 's/Bcast//' | cut -d: -f2


                                                  How it works:



                                                  • ifconfig

                                                  • Grep for lines containing "inet addr"

                                                    • These lines contains the IPs.


                                                  • Grep for lines that do not contain "127.0.0.1"

                                                    • We usually do not care about localhost.

                                                    • -v is inverted grep


                                                  • From remaining lines, remove the "Bcast"

                                                  • Cut field 2 using ":" as a delimiter

                                                    • Prints the answer.







                                                  share|improve this answer














                                                  share|improve this answer



                                                  share|improve this answer








                                                  edited Dec 18 '16 at 21:28









                                                  kenorb

                                                  7,716364103




                                                  7,716364103










                                                  answered Dec 2 '13 at 18:47









                                                  ohlemacher

                                                  1493




                                                  1493




















                                                      up vote
                                                      -2
                                                      down vote













                                                      ifconfig en0 | grep status


                                                      This will show the status of the ethernet connection en0






                                                      share|improve this answer


























                                                        up vote
                                                        -2
                                                        down vote













                                                        ifconfig en0 | grep status


                                                        This will show the status of the ethernet connection en0






                                                        share|improve this answer
























                                                          up vote
                                                          -2
                                                          down vote










                                                          up vote
                                                          -2
                                                          down vote









                                                          ifconfig en0 | grep status


                                                          This will show the status of the ethernet connection en0






                                                          share|improve this answer














                                                          ifconfig en0 | grep status


                                                          This will show the status of the ethernet connection en0







                                                          share|improve this answer














                                                          share|improve this answer



                                                          share|improve this answer








                                                          edited Apr 20 at 2:37









                                                          fpmurphy1

                                                          2,260915




                                                          2,260915










                                                          answered Apr 20 at 2:18









                                                          swartenfagen

                                                          1




                                                          1



























                                                               

                                                              draft saved


                                                              draft discarded















































                                                               


                                                              draft saved


                                                              draft discarded














                                                              StackExchange.ready(
                                                              function ()
                                                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f103241%2fhow-to-use-ifconfig-to-show-active-interface-only%23new-answer', 'question_page');

                                                              );

                                                              Post as a guest













































































                                                              Popular posts from this blog

                                                              How to check contact read email or not when send email to Individual?

                                                              Bahrain

                                                              Postfix configuration issue with fips on centos 7; mailgun relay