Manage Network Connections using Batch Scripts

Windows offer many different ways to manage your Network Connections including adapters status/configuration and network routing from the Command Line. The most frequently used are the Windows Management Instrumentation Command Line and the Netsh Command Line utility. Those commands can be used to automate Network Configuration in Batch Scripts.

List Available Network Interface Cards (NIC)

wmic nic get name,index,macaddress

Disable/Enable a NIC

Disable

wmic path win32_networkadapter where index=[Enter NIC Index here] call disable

Enable

wmic path win32_networkadapter where index=[Enter NIC Index here] call enable

You must run these commands as administrator, otherwise you may get a ReturnValue of 5. The default ReturnValue is 0, which means that no error occured.

List Network Connections

Using netsh you can view your Network Connections (both interface and IP configuration) using the command:

netsh interface ip show config

Set static/dynamic IP Address

Another way to list all the available interfaces beside wmic, is by using the command:

netsh interface show interface

After finding the name of the interface you want to set a Static IP Configuration, then run the command for the configuration you want:

Static

netsh interface ipv4 set address "[Interface Name]" static address=[IP] mask=[Subnet Mask] gateway=[Gateway IP]

Dynamic

netsh interface ipv4 set address "[Interface Name]" dynamic

Route Specific Subnet to a specific NIC

You can view all active and persistent network routes using the command:

route print

This command also list the available NIC adapters (different index than previously with wmic), and from here you have to remember the index of the interface you want to route the traffic to.

Add a new route

Run the following command to reroute all the specified traffic to the specific NIC card

route ADD [Destination] MASK [Subnet Mask] [Gateway IP] IF [Interface Index in HEXADECIMAL]

So for example if we want to reroute all the traffic of the subnet 192.168.200.0/24 with Gateway IP 192.168.200.254 to the NIC Card with Decimal Index of 12 then the command should be:

route ADD 192.168.200.0 MASK 255.255.255.0 192.168.200.254 IF 0xC

Add a persistent route

After executing the previous command all the traffic to the 192.168.200.0/24 network will be routed through the Network interface with the Index of 12, until next reboot. If you want to make the routing persistent you should use the -p flag as follows:

route -p ADD 192.168.200.0 MASK 255.255.255.0 192.168.200.254 IF 0xC

Make oVirt VM Reflect Host Hardware Properties

Due to the fact that Hypervisors stand between hardware and software, they sometimes disrupt the proper communication between the two causing the software to fail. One such case is when software is locked on specific hardware, for example Microsoft Windows Server ROK.

If you follow the default procedure and install the OS directly on the server then everything runs fine without any issues. But what happens when you want to install the OS as a Virtual Machine on the same server? Well if you are using oVirt as your virtualization solution then you get the following message:

Failed BIOS Lock

Continue reading Make oVirt VM Reflect Host Hardware Properties

Mount a Raspberry PI image under Linux

Every operating system, has a way to mount file systems from devices or image files and include them in the file system. Under Linux the mount command instructs the operating system for an existing file system and associates it with a particular mount directory. Using the offset parameter of the mount command it’s possible to mount a Raspberry PI image to a directory and interact with it.

Continue reading Mount a Raspberry PI image under Linux

Raspberry PI RDP Thin Client

Updated 14/04/2021
Thin Clients, are computers which are optimized to establish a remote connection to a server and run using the remote resources. Usually those systems are not meant to be used for intensive tasks or gaming and they are mostly found in office environments. In the following guide you will find out how to use a Raspberry PI to connect to a local Windows Computer using Microsoft’s RDP Protocol.
Every version of Microsoft Windows following the release of Windows XP includes a Remote Desktop Connection (RDC) client (mstsc.exe). The Remote Desktop Connection is accomplished through the Client using the Remote Desktop Protocol a proprietary Microsoft Protocol which provides a graphical interface to connect to another computer.

Continue reading Raspberry PI RDP Thin Client

Custom MAC Address Linux Service

MAC Addresses are unique for each Network Interface Controller (NIC) and most often are not configurable. Taking advantage of this fact in combination with the Organizationally Unique Identifier(OUI), many Network scanners use the MAC Address in order to determine the manufacturer of a Network Device or even the device type. As you can read in RFC 7042:

48-bit MAC "addresses" are the most commonly used Ethernet interface identifiers. Those that are globally unique are also called EUI-48 identifiers. An EUI-48 is structured into an initial 3-octet OUI and an additional 3 octets assigned by the OUI holder or into a larger initial prefix assigned to an organization and a shorter sequence of additional bits so as to add up to 48 bits in total.

Here you can find a complete list of the registered OUIs from IEEE and here the Wireshark OUI Lookup tool.

Continue reading Custom MAC Address Linux Service

Arduino Network Tester

How many times you wanted to know if an Ethernet plug or port has internet connectivity and you had to bring your laptop or a cable from the next room to check? And how many times the only tools available were the simple Network Cable tester and your provider’s Modem or Router? For me that was a common issue and of course there was no easy, "plug and play" solution (at a reasonable price!!). Taking these into consideration I decided to give a solution by making a simple optimization to the most common Network tool. Arduino Network Tester, extends the functionality of the well-known Network Cable tester by adding DHCP, DNS and Internet connectivity tests using an Arduino Pro Mini and a W5500 Ethernet Shield with an overall cost of less than €15!
Arduino Network Tester

Continue reading Arduino Network Tester

Raspberry PI as a Serial Device

There are many tutorials explaining how to set up your Raspberry PI as a Serial Device. Almost all of those tutorials explain how to setup your Raspberry as a Serial Console, which will act similar to a SSH connection. The current tutorial takes a different approach. You will find out how to turn your Raspi to a Serial USB Gadget, and how to control what you redirect to the Gadget’s Serial port in order to be available to the machine it will connect to. Using socat, commands we will redirect Serial data received over IP to the Gadget Serial port or data from the on-board UART protocol to the Gadget port.

Continue reading Raspberry PI as a Serial Device

Raspberry PI as a SOCKS Server

Raspi Socks Diagram

How it works

The SOCKS protocol is being used to exchange packets between a server and a client through a Proxy server. Expanding the Remote Drone’s abilities, we can configure the "Middle Host" to act as a PROXY Server and redirect all of our requests to the "Remote Drone". With this configuration, all the traffic will be transferred through the "Remote Drone" and we will be able to access the remote network, or even the Internet through the remote’s Network ISP Modem.

Continue reading Raspberry PI as a SOCKS Server