有没有办法获取aws的弹性网络接口的MAC地址,使用aws JAVA SDk
答案 0 :(得分:1)
我可以使用describe-network-interfaces
命令使用AWS-CLI获取MAC地址,如下所示:
$ aws ec2 describe-network-interfaces --network-interface-ids eni-eaxxxxd | jq ".NetworkInterfaces[].MacAddress"
"06:56:88:b9:82:17"
同样在Ruby-SDK中,有一种方法可以使用describe_network_interfaces-instance_method
来提取MAC地址我搜索了DescribeNetworkInterfacesRequest的JAVA SDK文档,似乎确实提供了mac地址。但是,我不擅长阅读JAVA API文档。
由于我能够使用AWS-CLI和RUBY-SDK获取MAC地址,因此API已就绪。只需要在JAVA-SDK文档中获取确切的方法。
答案 1 :(得分:0)
// get network interface of instance and from that get mac address
List<InstanceNetworkInterface> networkInterfaces = inst.getNetworkInterfaces();
for (InstanceNetworkInterface instanceNetworkInterface : networkInterfaces) {
System.out.println("=-------------"+instanceNetworkInterface.getNetworkInterfaceId());
DescribeNetworkInterfacesRequest describeNetworkInterfacesRequest = new DescribeNetworkInterfacesRequest();
describeNetworkInterfacesRequest.withNetworkInterfaceIds(instanceNetworkInterface.getNetworkInterfaceId());
DescribeNetworkInterfacesResult describeNetworkInterfacesResult = amazonEc2.describeNetworkInterfaces(describeNetworkInterfacesRequest);
List<NetworkInterface> networkInterfaces1 = describeNetworkInterfacesResult.getNetworkInterfaces();
for (NetworkInterface networkInterface : networkInterfaces1) {
System.out.println(networkInterface.getMacAddress());
}
}
//-------------------------