$ipAddr=$(/usr/local/bin/ipas"${interface}"|sed-rn's|\W*inet[^6]\W*([0-9\.]{7,15}).*$|\1|p')# or via `/sbin/ifconfig`$ipAddr=$(/sbin/ifconfig"${interface}"|sed-rn's|^\s+inet\s+([0-9\.]+))
#!/bin/bashwhileread-rline; do sname=$(echo"$line"|awk-F"(, )|(: )|[)]"'{print $2}') sdev=$(echo"$line"|awk-F"(, )|(: )|[)]"'{print $4}')# echo "Current service: $sname, $sdev, $currentservice"if [ -n"$sdev" ]; then ifout="$(/sbin/ifconfig "$sdev" 2>/dev/null)"echo"$ifout"|grep'status: active'>/dev/null2>&1 rc="$?"if [ "$rc"-eq0 ]; then currentservice="$sname" currentdevice="$sdev" currentip=$(echo"${ifout}"|sed-rn's|^\s+inet\s+([0-9\.]+).*$|\1|p') currentmac=$(echo"$ifout"|awk'/ether/{print $2}')# may have multiple active devices, so echo it hereecho"$currentservice, $currentdevice, $currentmac, ${currentip}"fifidone<<<"$(networksetup-listnetworkserviceorder|grep--color=none 'Hardware Port')"
find local device ip address
$arp-a
networksetup
show network information
$networksetup-listnetworkserviceorderAnasterisk (*) denotes that a network service is disabled.(1) USB10/100/1000LAN(HardwarePort:USB10/100/1000LAN,Device:en7)(2) Wi-Fi(HardwarePort:Wi-Fi,Device:en0)...# or$networksetup-listallnetworkservicesAnasterisk (*) denotes that a network service is disabled.USB10/100/1000LANWi-FiBluetoothPANThunderboltBridge
$networksetup-listallhardwareports# list detail of hardware$networksetup-getinfo'USB 10/100/1000 LAN'DHCPConfigurationIPaddress:192.168.1.10Subnetmask:255.255.255.0Router:192.168.1.1ClientID:IPv6:AutomaticIPv6IPaddress:noneIPv6Router:noneEthernetAddress:**:**:**:**:**:**# or: https://apple.stackexchange.com/a/368047/254265$system_profilerSPAirPortDataTypeWi-Fi:SoftwareVersions:...
$networksetup-setairportpoweren0on# not available anymore$sudo/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport-sSSIDBSSIDRSSICHANNELHTCCSECURITY (auth/unicast/group)Customer**:**:**:**:**:**-7511NCNWEPCorpWLAN**:**:**:**:**:**-721YCNWPA2(802.1x,Unrecognized(0)/AES/AES)Guest**:**:**:**:**:**-711YCNNONE
disable ipv6
$networksetup-listallnetworkservicesAnasterisk (*) denotes that a network service is disabled.USB10/100/1000LANWi-FiBluetoothPANThunderboltBridge# disable$networksetup-setv6off'USB 10/100/1000 LAN'$networksetup-setv6offWi-fi# undo$networksetup-setv6automatic'USB 10/100/1000 LAN'$networksetup-setv6automaticWi-Fi
Host name—Route is to a host rather than to a network
R
Reject—Set by ARP when an entry expires
D
Dynamic—Route added by a route redirect or RIP
M
Modified—Route modified by a route redirect
C
Cloning—A new route is cloned from this entry when it is used
L
Link—Link-level information, such as the Ethernet MAC address, is present
S
Static—Route added with the route command
check route
show all
# linux-like route -n$netstat-nr# ipv4$netstat-nr-finet# ipv6$netstat-nr-finet6# via `ip route`$iprouteshow
show particular ip
$routeget<ip.address>routeto:ec2-1-1-1-1.compute-1.amazonaws.comdestination:ec2-1-1-1-1.compute-1.amazonaws.comgateway:192.168.0.1interface:en0flags:<UP,GATEWAY,HOST,DONE,STATIC>recvpipesendpipessthreshrtt,msecrttvarhopcountmtuexpire0007711015000# or via `ip route`$iprouteget1.1.1.11.1.1.1via192.168.0.1deven0src192.168.6.55