Last active
February 8, 2016 03:45
-
-
Save akira345/93dff2ba1ca8a57ac9ed to your computer and use it in GitHub Desktop.
AWSでVPC/サブネット上でプライベートIPがぶつかっていないかチェックするメモ。AWS SDK for Ruby V1使用。動くRubyスクリプトではないので注意。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vpc_id = "" | |
subnet_id="" | |
private_ip = "" | |
#すでにローカルIPが使用されていないか? | |
ary_ips = [] | |
ec2.client.describe_network_interfaces(filters: [{ name: "vpc-id",values: [vpc_id]},{name: "subnet-id",values: [subnet_id]}])[:network_interface_set].each {|d| | |
d[:private_ip_addresses_set].each {|dd| | |
ary_ips.push(dd[:private_ip_address]) | |
} | |
} | |
if ary_ips.include?(private_ip) | |
pp "Duplicate Private IP!!" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment