mac查IP地址

方法一:

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

茶如影

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值