Convert Larger CIDR (eg /16) to list of /24 - ip

I have a hardware firewall that won't accept CIDR entries larger than /24. I often need to block larger ranges (eg /17 or /20) but typing out all those /24 CIDRs is not practical.
I'm hoping someone has a way to do this - either with an online tool, something I can install on a Linux server, something I can install on a Windows computer, or even an Excel trick if that's possible. I'm desperate.
Example:
I want to enter this: 192.168.0.0/17
And get back a result like this:
192.168.0.0/24
192.168.1.0/24
192.168.2.0/24
192.168.3.0/24
192.168.4.0/24
... all the way to ...
192.168.127.0/24
This tool sort of does what I want, but has so much extra data in the results that it would be just as much work to clean it up as it is to enter each /24 manually.
http://jodies.de/ipcalc?host=192.168.0.0&mask1=17&mask2=24

If you want to write a bit of Java, then the following code, using the IPAddress Java library (Disclaimer: I am the project manager) handles this. If you do not know Java programming, then you'd need to start with a crash course in Java.
IPAddress addr = new IPAddressString("192.168.0.0/17").getAddress();
IPAddress shifted = addr.adjustPrefixLength(7, false);
Iterator<? extends IPAddress> iterator = shifted.prefixBlockIterator();
while(iterator.hasNext()) {
System.out.println(iterator.next());
}
Output:
192.168.0.0/24
192.168.1.0/24
192.168.2.0/24
192.168.3.0/24
...
192.168.125.0/24
192.168.126.0/24
192.168.127.0/24

Related

Can't connect to NAS, even via IP

Background
Been having a lot if issues with this problem. Randomly PC won't connect to NAS for apparently no reason at all, while others it works. I read tonne of posts about various fixes, some worked sometimes, some didn't, but lately none did. Restarting PC, NAS, or router didn't work, nor did changing settings, checking firewall, antivirus, etc.. Finally I managed to figure it out.
Our nas allow us to make a network name to access it by, like \\MyServer, but sometimes when power goes out, or we have to restart router, this address won't work because the server's local IP had changed, and the address was still cached on our computer to the old one.
The reason can be one of many. In my case, it was none that I could find common answers to.
TL;DR
I randomly can't connect to my NAS via \\MyServer or it's IP \\10.0.0.3, but other PC's can.
I suggest using Synology Assistant. This will find the NAS on the network if it is physically in range.
Then I highly recommend to use a fix IP address for the NAS. It is no good idea having servers with DHCP...
Reason (in my specific case)
Sometimes the PC would only connect to the NAS via IPv6 (almost feel like it does it on a whim), IPv4 won't work at all. That or the old IP is cached on your system.
IPv4 looks something like one of these: 10.0.0.5, 172.16.0.2, or 192.168.0.0
IPv6 looks something like: fe80::842a:a43d:3123:1332
Quick fix attempt first
First, just try opening command prompt and enter ipconfig /flushdns, then try to connect to your usual \\MyServer address, see if that works now.
Didn't work?
What you can try is to see if you can connect via its IPv6 — but first you need to somehow obtain it.
Step 1 In command prompt, type ping MyServer (replaced with whatever name you have), and it see if it manages to ping it. If it does, it will resolve the IP and show an IPv6. If it shows IPv4 or can't connect at all, see further down.
Step 2 Locate the IPv6 at the top, remove % and number after.
Step 3 Replace : with -. Note doubles if you have that: :: with --.
Step 4 Prefix the usual \\ at the start, and add .ipv6-literal.net at the end. Now try to connect to the server using that. With the IPv6 example above, it'd be something like: \\fe80--842a-a43d-3123-1332.ipv6-literal.net
Ping shows IPv4?
Try to ping with one of the other computers, or if you are able to, login to the web dashboard or equivalent on one of those computers, and see if you can find any information about the server's IP's, with goal of finding its IPv6.
Once found, do steps above.
Done!
Other stuff:
IPv6 in browser — remove the % and number, put IP inside brackets [] and then connect. Example: http://[fe80::842a:a43d:3123:1332].
Creating alias of the weird IPv6:
Step 1 Right click Notepad, and open as Administrator
Step 2 Go to File → Open, change the dropdown above 'open' from Textfiles (*.txt) to All files (*.*).
Step 3 Locate the hosts file, located at C:\C:\Windows\System32\drivers\etc\ and open
Step 4 At the bottom, write the IPv6 with the colons AND the %##, then a space, then the alias you want it to use (case insensitive). Example: fe80::842a:a43d:3123:1332%15 MyAlias and save. You should now be able to use \\MyAlias to connect to it.
NOTE The %## number is unique to each computer. E.g. your computer gets %15, the next get %7. The rest of the IP is identical. To get the %## number of a different PC, write ipconfig in its command prompt. It should list its own IPv6 with its appended %## at the end.
Another note: If you need to change an IP in the hosts file of an IP that no longer work, you also need to use ipconfig /flushdns again.

How to disable networking traffic / connections in Nix language in Nixos?

Have searched https://nixos.org/nixos/options.html#networking for networking options. And I have not found something that may achieve this:
I would like a configuration which ensures that users don't have any network traffic.
As it would be a nix generation, running $ nixos-rebuild switch on a configuration.nix file without this network option, could put the computer network communication back to normal.
I have tried mannually calling $ sudo systemctl stop network-manager, but it had no results.
Similarily, nothing seemed to change when I tried modifying this in configuration.nix and then $ nixos-rebuild switch
networking.networkManager.enable = false
Any idea ?
Should I manually deal with each of the network interfaces ?
With everything else at defaults, this may be as simple as:
networking.useDHCP = false;
networking.interfaces = {};
Of course, you could also go more heavy-handed -- putting all your network hardware into the blacklistedKernelModules list, f/e -- and personally, I'd recommend that.

Connecting to specific ip and port

This summer I am working at a computer summer camp. All the kids love playing slither.io
The kids really want to play on the same world but slither.io doesn't provide an easy way to do this and instead spreads them out through the multiple servers. I have limited networking knowledge but am somewhat familiar to working with webSockets.
What I was hoping I could do to get them on the same world was:
Have one kid connect to slither.io and enter a game.
Once they were in open the dev tools in Chrome and get the ip and port that they were connected to with bso.ip and bso.po
The other kids could then using the dev tools run
connect("ws:\\123.123.123.123:444")
with the ip and port set to whatever the first kid had.
Running connect gets them into slither.io but 90% of the time it is on a different server/ip address
Is there a way to get them all in the same world?
Connecting to the WebSocket alone is not enough to register the game to use it. Looking at the source code, there is a function forceServer, which sets the IP and Port:
function forceServer (a, b) {
sos = [];
forcing = true;
bso = {};
bso.ip = a;
bso.po = b;
bso.ac = 999;
sos.push(bso);
}
The sos array is global and used later on to connect to the WebSocket and register the game instance. The exact details are difficult to follow because it's all minified in game73gig.js, but I think this function sets everything up.
Run the following in the Console instead:
forceServer("123.123.123.123", "443");
There is a Tampermonkey snippet to inject a form element and JavaScript to do this automatically. I haven't tried it but it's called Slitherio-Plugin.

MAC changing program or daemon?

I'm currently have a program which creates a list of all MAC addresses and corresponding names and IP addresses on my network.
I was wondering if it's possible (theoretically) to create a background program which, every hour, would change your MAC address based on the list you provide. The list would continuously be updated by the already stated program.
I'm good with Python and Batch, but I'm running a Mac system right now (which is what I want to implement this program on) and have little knowledge of bash when it comes to the network itself, or of creating background tasks that are time sensitive.
If this is too broad of a question, please do let me know.
Thank you!
You could accomplish this with a simple script, and periodically run it using cron.
Here is an example of how to change your MAC address from a shell script (adapted from here)
#NETWORKING="/etc/init.d/networking" # On some systems
NETWORKING="service network" # On my Fedora 16 box
$NETWORKING stop
ifconfig eth0 hw ether 02:01:02:03:04:08
$NETWORKING start
So you'd need to come up with a way to randomize that MAC address.
Then, use crontab -e to add it to your crontab. Here is a quick reference for crontab.
Here's some python to generate a random MAC address and change it. Only the MAC generation has been tested (for obvious reasons). Also note, you may want to limit the range on some of the bytes in the MAC address, but that is outside the scope of my answer.
from subprocess import call
import random
mac = [random.randint(0, 0xFF) for i in range(6)]
macstr = ':'.join(['{:02X}'.format(x) for x in mac])
print 'Changing MAC address to', macstr
call(['service', 'network', 'stop')
call(['ifconfig', 'eth0', 'hw', 'ether', macstr])
call(['service', 'network', 'start')

Finding the correct "network interface" number for IPv6

I am trying to use Boost for some IPv6 and multicast network communication. I need to construct an IPv6 multicast socket that uses a specific network interface index.
I was able to find the correct multicast option to set the network interface index in boost/asio/ip/detail/socket_option.hpp:
explicit multicast_request(const boost::asio::ip::address_v6& multicast_address, unsigned long network_interface = 0)
The problem is, I don't know how to find the correct value for the "network_interface" parameter. Is there a way to get the network_interface value using a local IPv6 address that I can provide? I looked in the documentation and examples, but couldn't find anything.
-- Dylan
Each platform provides APIs to enumerate the network interfaces, e.g. getifaddrs for many Unixes and GetAdaptersAddresses for Windows. Note on Windows there is a separate numerical space for IPv4 and IPv6 adapters which makes the API call if_nametoindex quite confusing.
You may wish to inspect the methods I employed in OpenPGM for portability, considering Windows doesn't really have useful adapter names:
http://code.google.com/p/openpgm/source/browse/trunk/openpgm/pgm/getifaddrs.c
http://code.google.com/p/openpgm/source/browse/trunk/openpgm/pgm/nametoindex.c
http://code.google.com/p/openpgm/source/browse/trunk/openpgm/pgm/indextoaddr.c
http://code.google.com/p/openpgm/source/browse/trunk/openpgm/pgm/indextoname.c
I don't think there's a platform-independent way to figure this out, just as there is no portable solution to enumerating the local addresses.
On Linux, you can find what you want in the second column of /proc/net/if_inet6, which is also available more robustly through the rtnetlink(7) interface.

Resources