I just tried to use Ruby's IPAddr class and I've been wondering if it is possible to create a new IPAddr with a netmask. To clarify my issue this is what I've done:
IPAddr.new "192.186.2.253/24"
=> #<IPAddr: IPv4:192.186.2.0/255.255.255.0>
What I would expect is to get this:
#<IPAddr: IPv4:192.186.2.253/255.255.255.0>
If I use the to_range method, the ip addresses are matching the second example.
Did i get anything wrong with this class? How can I achieve to initialize such an ip address without cutting off the host id.
Thanks a lot
When a netmask is supplied, the address is treated as a network address, not a host address, at least that's how I interpret your findings in combination with the docs:
If a prefixlen or a mask is specified, it returns a masked IP address.
I assume, by "masked IP address", the author means a network address, at least that's what makes the most sense given the behavior you observed and the description of the IPAddr#to_range method.
Related
I need to create a function in Google sheet to get my external (public) IP address
I tried use function =IMPORTXML("https://api.myip.com","//body"), but this method shows diffrint IP address not my external IP address
the reason the IP is different is because you are getting the IP of Google Sheets location not your IP
The following solution makes use of a custom menu in the Spreadsheets -
function onOpen(e) {
SpreadsheetApp.getUi()
.createMenu('My Menu')
.addItem('Get IP', 'getIP')
.addToUi();
}
function getIP() {
SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().appendRow([JSON.parse(UrlFetchApp.fetch('https://api6.ipify.org?format=json')).ip]);
}
You're free to modify the script to place said IP anywhere in the sheet, as required.
Also, I'm making use of the IPv6 address, as opposed to IPv4 but should you want to switch it to IPv4, replace the URL from the code to https://api.ipify.org?format=json - you may find this resource here.
I've asked out & around and this cannot (in any way) be achieved via a custom formulae, as such formulas run within a wrapper of sorts (that do not interact with any client-side elements). Hope this helps.
Edit note
Adding a way to insert external IP using custom menu to the specific cell (current cell, to be precise) -
function onOpen(e) {
SpreadsheetApp.getUi()
.createMenu('My Menu')
.addItem('Get IP', 'getIP')
.addToUi();
}
function getIP() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var currentCell = sheet.getCurrentCell();
var ip = JSON.parse(UrlFetchApp.fetch('https://api6.ipify.org?format=json')).ip;
currentCell.setValue(ip)
}
By using this method, the IP would be added to the cell that has been selected.
You may wonder why current cell was chosen instead of active cell - well, the answer to that is because the document prefers us to do so :) I bet it would work even if we were to use active cell (haven't tested that though but I don't see a reason why it wouldn't)
It's not possible to use a Google Sheets custom function or Google Apps Script server side address to get you external IP because the related code is executed on the server side and Google Apps Script services doesn't include methods to get that but you could use client-side code to the get the external IP address. Additional, if it is required to send the IP address to an spreadsheet, the you could use do that by using google.script.run or the Google Sheets API.
NOTE: The closest Google Apps Script classes are Class Session and Class User.
Related
How to get client's IP address using JavaScript?
References
https://developers.google.com/apps-script/reference
For a given virtual address 'addr' I'd like to check if the page address 'addr' is in, is cache-able?
Motivation: I'd like to verify certain attributes as cache-able, readable, writable, executable.
How can I do that?
After creating VPC using standard private IP address and their subnets in Alibaba Cloud VPC.
The standard IP address ranges include 10.0.0.0/8, 172.16.0.0/12,
192.168.0.0/16 and the default is 172.16.0.0/12.
I am not able to modify CIDR Block
I appreciate any assistance with this.
It is not possible to change the vpc cidr block after creation.
See the documentation link https://www.alibabacloud.com/help/doc-detail/65430.htm
You need to create the new VPC with new CIDR range.
After creating the VPC you cannot modify the CIDR Block. If you want to modify the CIDR range then the optimal way is to create the new VPC with desired CIDR Range.
You can confirm the same on the Alibaba official documentation as well
I'm trying to add a new route using the netlink package. The equivalent I need is ip route add $P1_NET dev $IF1 src $IP1 table $T1. The issue is that I don't know what field corresponds to the dev parameter. Is there a mapping somewhere or can I use the interface index instead its name ("dev")?
Looking at the link you sent, I'd guess IifName. And looking at the code seems to confirm that.
WinAPI's GetAdaptersInfo() fills structure AdapterInfo which has field called AdapterName. What does this field mean? What's the point in it? In my case it holds string "{C01E7744-531D-401F-8EA6-D76D3AF35555}" (including curly braces).
P.S.: beside AdapterName there is pretty clear (for me) field called Description with value (in my case):
"Realtek RTL8102E/RTL8103E Family PCI-E Fast Ethernet NIC - VirtualBox Host Interface Networking Driver Miniport"
what makes me even more confused with AdapterName.
Looks like it's just a GUID that windows assigns to the adapter, probably as a unique identifier that you can use in some other API call to reference that adapter specifically. For example GetAdapterIndex.
Most IP helper functions seem to take an adapter index, but if you had an app that manipulated network adapters, you probably wouldn't want to store the index of a specific adapter in your app as that could change when adapters are added or removed. So you would store the name of the adapter, then use GetAdapterIndex to get the index for it when needed.
Its formatted like so
GetAdapterIndex(L"\\device\\tcpip_{FD2046B5-1DA0-40A2-9F28-DE4D6F0EBE22}", &index);
I have no idea where this is actually documented officially but found it sourced here: https://chromium.googlesource.com/external/qemu/+/refs/heads/master/qga/commands-win32.c
Description is the user-friendly name associated with AdapterName.
Sources:
http://www.delphigroups.info/2/8/215347.html