简体   繁体   中英

How to figure out if the network the mac is connected to is a WiFi or cable network or the like

First off, you guys are all really helpful - thank you a lot!

Is there a way to figure out what type of network a Mac is connected to? WiFi? Cable? USB Modem? Any Cocoa / Foundation framework I can use to figure that out?

Thank you, Matthias

You can tell whether the Mac is using WiFi, whether it is using a modem, and whether it is using hard Ethernet (which could be cable, DSL, or something else). Note that these are not mutually exclusive, there may be multiple connections of a single type (I have two Ethernet ports, for example), and that being connected to an IP network does not necessarily mean connection to the Internet.

You'll probably find the System Configuration API helpful. See also the framework reference .

You may also want to look at the source for HardwareGrowler in the Extras folder of the Growl source code .

You could ask for the route table and see what the default route is, that would tell you to some degree of accuracy what the active connection is.

This obviously has a lot to do with how you define 'some degree of accuracy'. Generally the main internet connection will also be the default route. I'm assuming you also want active connection to mean 'internet connection'.

netstat -rn Routing tables

Internet: Destination Gateway Flags Refs Use Netif Expire

default 192.168.0.1 UGSc 22 14 en1

so for me, my default route goes out the en1 interface. I think you need to be a lot more specific on what you mean by 'active/current' means to you.

CAVEAT: just because my default gw is on en1, does not necessarily mean that's where all my inet traffic goes. (it happens to be true in my case, but don't count on it as truth, but would probably be correct more than half the time).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM