Skip to content

Commit

Permalink
TIL: macos networksetup
Browse files Browse the repository at this point in the history
  • Loading branch information
pew committed Jan 12, 2025
1 parent b4a7eee commit e8553c4
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions man/networksetup.md
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
```

0 comments on commit e8553c4

Please sign in to comment.