Foundation-Host

  • Host 类的作用

1.获取网络的名字和主机的地址信息
2.可以获取当前主机的名称和地址以及查看其它主机的名称和地址

  • 获取自己主机名称和地址
let host = Host.current()
print(host.name)
print(host.address)
print(host.localizedName)

运行结果:

Optional("xudeMacBook-Air.local")
Optional("fe80::10af:2b7e:df61:******")
Optional("xu的MacBook Air")

  • 获取其它的主机名和地址
 let host = Host.current()
 print(host.names)
 print(host.addresses)

运行结果:

["xudeMacBook-Air.local", "localhost"]
["fe80::c2d:e20d:121:*", "fe80::10af:2b7e:df61:*", "fe80::20f2:e6ff:fea7:24f8%awdl0", "fe80::ae3:34b5:bdfa:b832%utun0", "192.168.110.66", "172.17.109.4", "127.0.0.1", "fe80::1%lo0", "::1"]

  • 查看网络下的ip地址和对应的mac地址

在命令行输入

  arp -a
Foundation-Host_第1张图片
不忘初心,方得始终

你可能感兴趣的:(Foundation-Host)