Get list of network interfaces in a system

2,467 views
Skip to first unread message

Sam Fourman Jr.

unread,
Aug 14, 2014, 7:49:31 AM8/14/14
to golan...@googlegroups.com
Does anyone know of a package that will ask a linux/BSD system for a list of network interface names?

like ifconfig

for example on FreeBSD
sfourman@GoDev ~/go/src/freebsd % ifconfig -l
re0 lo0

thanks in advance
--

Sam Fourman Jr.

egon

unread,
Aug 14, 2014, 7:55:13 AM8/14/14
to golan...@googlegroups.com


On Thursday, 14 August 2014 14:49:31 UTC+3, Sam Fourman Jr. wrote:
Does anyone know of a package that will ask a linux/BSD system for a list of network interface names?


+ egon

Jan Mercl

unread,
Aug 14, 2014, 7:56:42 AM8/14/14
to Sam Fourman Jr., golan...@googlegroups.com
On Thu, Aug 14, 2014 at 1:49 PM, Sam Fourman Jr. <sfou...@gmail.com> wrote:
> Does anyone know of a package that will ask a linux/BSD system for a list of
> network interface names?

The net package provides that: http://play.golang.org/p/BE-PBpoRm9

-j

Sam Fourman Jr.

unread,
Aug 15, 2014, 3:17:32 PM8/15/14
to Jan Mercl, golan...@googlegroups.com
This works GREAT! the go standard library is extremely comprehensive, as a new user I can say I underestimated it.
--

Sam Fourman Jr.

angan...@gmail.com

unread,
Aug 15, 2014, 5:06:33 PM8/15/14
to golan...@googlegroups.com, sfou...@gmail.com
When I run this program in Windows 7, I got something like these "{A3768A7A-8E5F-42F8-81E3-3BCAACEC9FBE} {DA57743C-8273-4534-AA8E-8EDF0B9CE9FD}" instead of the names. 

How can I get the network interface names in Windows?

Steve McCoy

unread,
Aug 15, 2014, 5:57:21 PM8/15/14
to golan...@googlegroups.com, sfou...@gmail.com, angan...@gmail.com
Those are the names on Windows. What names are you expecting?

Andrew

unread,
May 10, 2016, 6:29:25 PM5/10/16
to golang-nuts, sfou...@gmail.com, angan...@gmail.com
Now I can get network adapter names in Windows 7 using Go 1.5.3 like the following:

C:\goproj\src\learn>go run try.go
MyNet
Local Area Connection
Loopback Pseudo-Interface 1

Thanks. 

Konstantin Khomoutov

unread,
May 11, 2016, 7:12:26 AM5/11/16
to Andrew, golang-nuts, sfou...@gmail.com
net.Interfaces() ?

Andrew

unread,
May 11, 2016, 2:30:35 PM5/11/16
to golang-nuts, angan...@gmail.com, sfou...@gmail.com
infs, _ := net.Interfaces()
for _, f := range infs {
fmt.Println(f.Name)
}
Yes. 
Reply all
Reply to author
Forward
0 new messages