Get IP with subnet mask for use with AWS EC2 SSH - amazon-web-services

When setting up an EC2 instance AWS Console has a useful feature to find your current IP address complete with subnet mask for whitelisting. Here is the UI I'm sure we have all seen.
This is convenient when you are setting it up but if you need to white list a remote DEV's home WIFI or you are using cloudformation it is not longer convenient to get the IP address this way.
So, is there a convenient way to print out your IP address complete with the subnet mask (/) from your terminal? I have not found one.

If you're on linux or mac it's fairly simple to do a ip addr show or assign to a variable with IP_ADDR=$(ip addr show).
On windows, there's a PowerShell module you can use.
Invoke-WebRequest ifconfig.me/ip
though that prints out more than just the IP, you can always parse it.

Ok, I realized I did not understand CIDR notation and subnet masking.
Basically AWS requires CIDR notation and CIDR notation allows you to specify a range of addresses. It works out that the /32 means a range of 0 so the address is everything to the left of the /.
So, to whitelist a single IP you say myIP/32

Related

EC2 Classic Link - Determine Classic IP Range

So, I am working to migrate from EC2 Classic to VPC (yeah, I know, long time in coming and this was an inherited platform).
I have created a VPC and when I go to turn on Classic Link, I get the following error:
The CIDR range of vpc-[id_here] overlaps with the Classic IP space
I looked and was not able to find a way to determine which IP Range(s) Classic uses. Is there a way to find out so I can make my VPC's not stomp all over it?
Thanks!
10.0.0.0/8 as documented here.
As in the comment above:
"VPCs that are in the 10.0.0.0/16 and 10.1.0.0/16 IP address ranges can be enabled for ClassicLink

open firewall for multiple IPs

I am trying to give the following IPs access t0 post data to mysql installed on VM google cloud (drupal8) i cannot figure out how to write the format correctly. error Invalid IP address or range. Use CIDR notation and enter the lowest IP address in the subnet.
174.129.249.162|65.17.248.|68.71.103.|184.73.155.222|184.72.56.152|184.72.56.199|184.73.192.230|184.169.131.85|52.0.132.63|52.71.25.2|52.71.19.16|52.71.25.60|52.71.25.97|52.11.235.107|52.35.106.209|52.32.146.111|52.25.210.125|52.33.176.145
The format should be 174.129.249.162/32 184.73.155.222/32 etc

How to add extra private IP's to a GCP instance?

I want to add multiple routable ip addresses to an ubuntu 14.04 GCP instance. What is the simplest method for achieving this?
Note: External IP addresses are disabled on my gcp instances.
Correct me if I am wrong, but the solution described in this post that uses gcloud routes seems to change the network and firewall configuration to add extra IP addresses to instances. I am looking for a different solution.
I would like to add IP addresses to instances without changing the networks or firewalls of a gcp project at all.
I would like to add random available IP addresses on the current network of a gcp instance and avoid manually assigning an IP address or IP address range to my instances?
I am really looking for a solution that is similar to openstacks nova add-fixed-ip command that does just this. You can find a description of nova add-fixed-ip here: https://ask.openstack.org/en/question/65198/how-to-assign-static-private-ip-address-to-a-running-guest-vm/

set dynamic ip in security group, in AWS hosting?

I have created a security group in aws.amazon.com hosting.
I have set SSH to custom IP.
My problem is that my IPs are dynamic with in a range:
For example,
217.206.204.200
217.206.203.215
217.206.201.295
I want to create one rule for SSH custom IPs. So that all IPs have starting 217.206 can connect to server.
How can I do this?
217.206.0.0/16
This expression in the "Custom IP" box would allow every IP from 217.206.0.0 through 217.206.255.255, inclusive.
This is called CIDR notation.
The numbet after the slash is the prefix. An IPv4 address is 32 bits wide. The prefix indicates which bits of the address being compared must match the address specified. In this case, if the first 16 bits of the address of the connecting machine are "217" followed by "206" then the remaining bits of the address can be anything, and the rule will match that source IP.
http://en.m.wikipedia.org/wiki/Classless_Inter-Domain_Routing#CIDR_notation

Get ip address of computer on network c++

I am trying to make a C++ program in Windows that will output all of the ip addresses on the network to a text file but I have not been able to find anything useful online for other computers on the network. I figured out how to query the registry and find the local ip but I dont even know where to start to find other ip addresses. I don't want a copy-paste cookie cutter code because I want to learn how it works so if I could just get a link or a book that will guide me in the right direction that would be great.
For what purpose do you want to gain these IPs anyway?
I suspect what you're looking for is a way to obtain all possible IPs in a given subnet, which can be done quite trivially for say, IPv4. You simply take the IP address of your machine or router, and apply the subnet mask to it using bitwise and. (eg, 192.168.1.20 & 255.255.255.0 = 192.168.1.0, called the base, or network address). The valid hosts in this network are basically all of the bits which are zero in the subnet mask (255 in the previous example). This means the range 192.168.1.0 - 192.168.1.255 (exclusive, as the network address and broadcast address are not valid IP addresses of hosts in the network) are valid IP addresses of hosts.
There's no truly reliable way for any machine on the network other than the router to obtain specific information as to which of these addresses are in use though, as the interaction between machines on a network is meant to be voluntary, not implicit. Most machines however are generally running some kind of protocol which enables them to discover each other for purposes like printer and file sharing.
You can attempt to ping each of the possible host addresses in the network, or port scan, or talk to them with some protocol they might know. Alternatively you can use the broadcast address with a known protocol to ask all machines on the network to report back to you, and if they're running some software which talks that protocol, they'll respond with their own addresses.