-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--- | ||
date created: Sunday, January 12th 2025, 11:06:30 am | ||
date modified: Sunday, January 12th 2025, 11:10:41 am | ||
tags: | ||
- macos | ||
- networking | ||
--- | ||
|
||
# networksetup | ||
|
||
networksetup – configuration tool for network settings in System Preferences. | ||
|
||
## list all network services | ||
|
||
```shell | ||
networksetup -listallnetworkservices | ||
``` | ||
|
||
## get current active network connection | ||
|
||
```shell | ||
#!/bin/sh | ||
networksetup -listallnetworkservices | while read -r service; do | ||
if [ "$service" != "*" ]; then | ||
status=$(networksetup -getinfo "$service" | grep "IP address" | awk '{print $3}') | ||
if [ -n "$status" ] && [ "$status" != "none" ]; then | ||
echo "$service" | ||
break | ||
fi | ||
fi | ||
done | ||
``` |