方法一:
ifconfig
console输出:
zzz@MacBook-Air ~ % ifconfig
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
options=1203<RXCSUM,TXCSUM,TXSTATUS,SW_TIMESTAMP>
inet 127.0.0.1 netmask 0xff000000
inet6 ::1 prefixlen 128
inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1
nd6 options=201<PERFORMNUD,DAD>
gif0: flags=8010<POINTOPOINT,MULTICAST> mtu 1280
stf0: flags=0<> mtu 1280
en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
options=400<CHANNEL_IO>
ether 94:f6:d6:21:cb:24
inet6 fe80::1a:2115:3060:33da%en0 prefixlen 64 secured scopeid 0x4
inet 192.168.xx.xx netmask 0xffffff00 broadcast 192.168.xx.255
inet6 2409:8900:7e40:3d0f:1802:bd69:49a6:73b6 prefixlen 64 autoconf secured
inet6 2409:8900:7e40:3d0f:b1ac:47a0:63d5:6780 prefixlen 64 autoconf temporary
nd6 options=201<PERFORMNUD,DAD>
media: autoselect
status: active
en1: flags=8963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500
options=460<TSO4,TSO6,CHANNEL_IO>
ether 82:18:60:9a:8c:00
media: autoselect <full-duplex>
status: inactive
bridge0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
options=63<RXCSUM,TXCSUM,TSO4,TSO6>
ether 82:18:60:9a:8c:00
Configuration:
id 0:0:0:0:0:0 priority 0 hellotime 0 fwddelay 0
maxage 0 holdcnt 0 proto stp maxaddr 100 timeout 1200
root id 0:0:0:0:0:0 priority 0 ifcost 0 port 0
ipfilter disabled flags 0x0
member: en1 flags=3<LEARNING,DISCOVER>
ifmaxaddr 0 port 5 priority 0 path cost 0
nd6 options=201<PERFORMNUD,DAD>
media: <unknown type>
status: inactive
p2p0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 2304
options=400<CHANNEL_IO>
ether 06:f6:d6:21:cb:24
media: autoselect
status: inactive
awdl0: flags=8943<UP,BROADCAST,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1484
options=400<CHANNEL_IO>
ether b6:fd:66:22:ea:ca
inet6 fe80::b4fd:66ff:fe22:eaca%awdl0 prefixlen 64 scopeid 0x8
nd6 options=201<PERFORMNUD,DAD>
media: autoselect
status: active
llw0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
options=400<CHANNEL_IO>
ether b6:fd:66:22:ea:ca
inet6 fe80::b4fd:66ff:fe22:eaca%llw0 prefixlen 64 scopeid 0x9
nd6 options=201<PERFORMNUD,DAD>
media: autoselect
status: active
utun0: flags=8051<UP,POINTOPOINT,RUNNING,MULTICAST> mtu 1380
inet6 fe80::74c0:5dc8:9a74:d40b%utun0 prefixlen 64 scopeid 0xa
nd6 options=201<PERFORMNUD,DAD>
utun1: flags=8051<UP,POINTOPOINT,RUNNING,MULTICAST> mtu 2000
inet6 fe80::c77a:cdc5:7c98:f4b9%utun1 prefixlen 64 scopeid 0xb
nd6 options=201<PERFORMNUD,DAD>
输出信息太多,可查看硬件端口名,输入如下命令
networksetup -listallhandwareports
Console输出:
zzz@MacBook-Air ~ % networksetup -listallhardwareports
Hardware Port: Wi-Fi
Device: en0
Ethernet Address: 94:f6:d6:21:cb:24
Hardware Port: Bluetooth PAN
Device: en2
Ethernet Address: 94:f6:d6:21:cb:25
Hardware Port: Thunderbolt 1
Device: en1
Ethernet Address: 82:18:60:9a:8c:00
Hardware Port: Thunderbolt Bridge
Device: bridge0
Ethernet Address: 82:18:60:9a:8c:00
VLAN Configurations
===================
我们只需要查看WiFi端口,即en0
ifconfig en0
@MacBook-Air ~ % ifconfig en0
en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
options=400<CHANNEL_IO>
ether 94:f6:d6:21:cb:24
inet6 fe80::1a:2115:3060:33da%en0 prefixlen 64 secured scopeid 0x4
inet 192.168.xx.xx netmask 0xffffff00 broadcast 192.168.xx.xxx
inet6 2409:8900:7e40:3d0f:1802:bd69:49a6:73b6 prefixlen 64 autoconf secured
inet6 2409:8900:7e40:3d0f:b1ac:47a0:63d5:6780 prefixlen 64 autoconf temporary
nd6 options=201<PERFORMNUD,DAD>
media: autoselect
status: active
inet后的IP地址即为自己电脑的本地IP,此处用xx代替数字。
也可以用另一种:
ifconfig | grep "inet"
zzz@MacBook-Air ~ % ifconfig | grep "inet"
inet 127.0.0.1 netmask 0xff000000
inet6 ::1 prefixlen 128
inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1
inet6 fe80::1a:2115:3060:33da%en0 prefixlen 64 secured scopeid 0x4
inet 192.168.xx.xx netmask 0xffffff00 broadcast 192.168.xx.255
inet6 2409:8900:7e40:3d0f:1802:bd69:49a6:73b6 prefixlen 64 autoconf secured
inet6 2409:8900:7e40:3d0f:b1ac:47a0:63d5:6780 prefixlen 64 autoconf temporary
inet6 fe80::b4fd:66ff:fe22:eaca%awdl0 prefixlen 64 scopeid 0x8
inet6 fe80::b4fd:66ff:fe22:eaca%llw0 prefixlen 64 scopeid 0x9
inet6 fe80::74c0:5dc8:9a74:d40b%utun0 prefixlen 64 scopeid 0xa
inet6 fe80::c77a:cdc5:7c98:f4b9%utun1 prefixlen 64 scopeid 0xb
方法二:
nslookup localhost
zzz@MacBook-Air ~ % nslookup localhost
Server: 2409:8900:7e40:3d0f::9f
Address: 2409:8900:7e40:3d0f::9f#53
Name: localhost
Address: 127.0.0.1
截止2021年3月mac使用nslookup去查localhost命令无法直接显示ip地址。
但可以查看直接的网址ip:
zzz@MacBook-Air ~ % nslookup www.baidu.com
Server: 2409:8900:7e40:3d0f::9f
Address: 2409:8900:7e40:3d0f::9f#53
Non-authoritative answer:
Name: www.baidu.com
Address: 39.156.66.14
Name: www.baidu.com
Address: 39.156.66.18
在浏览器输入网址39.156.66.18
可以在跳转到百度页面。
总结:
#查看本地ip
ifconfig
ifconfig en0
ifconfig | grep "inet"
nslookup localhost
#查看所有硬件端口号
networksetup -listallhandwareports