Skip to content

Instantly share code, notes, and snippets.

@elico
elico / Prefer-Wifi-Connections.ps1
Last active October 13, 2024 10:32
Powershell Scripts to change the interfaces preference to WIFI and another to reset which will probably prefer the ethernet
# Get the network interfaces
$interfaces = Get-NetIPInterface | Where-Object {$_.InterfaceAlias -match "Wi-Fi" -or $_.InterfaceAlias -match "vEthernet" -or $_.InterfaceAlias -match "Ethernet"}
# Set a higher metric value for the Ethernet interface
foreach ($interface in $interfaces) {
Write-Host $interface.InterfaceAlias
if ($interface.InterfaceAlias -match "Ethernet") {
Write-Host "Ethernet Interface"
Set-NetIPInterface -InterfaceAlias $interface.InterfaceAlias -InterfaceMetric 100
@elico
elico / set-mgmnt-dhcp-client.ps1
Created June 5, 2024 20:56
Set a static address on a specific interface with specific ip string prefix
# Variables
$ipStringPrefix = "192.20.20." # Replace with the desired IP address prefix
$newIpAddress = "192.20.20.150" # Replace with the desired new static IP address
$newPrefixLength = 24 # Replace with the desired subnet mask length
# Find the interface by CIDR
$interfaces = Get-NetIPAddress | Where-Object {
$_.IPAddress.StartsWith($ipStringPrefix)
}
@elico
elico / hap-ac2-7.15-default.rsc
Created June 5, 2024 10:25
Mikrotik RouterOS AC2 7.15 default script
# 1970-01-02 00:02:40 by RouterOS 7.15
# software id = 8A8H-8IIG
#
script: #| Welcome to RouterOS!
#| 1) Set a strong router password in the System > Users menu
#| 2) Upgrade the software in the System > Packages menu
#| 3) Enable firewall on untrusted networks
#| 4) Set your country name to observe wireless regulations
#| -----------------------------------------------------------------------------
#| RouterMode:
@elico
elico / ppp-profile-on-up.rsc
Last active June 1, 2024 21:03
Example of ppp profile on-up script for a pppoe-client interface
{
:do {
:log info ("ppp on-up script for interface id: " . $interface . " Started" );
:local interfaceName [/interface/get $interface name];
:log info ("ppp on-up script for interface name: " . $interfaceName . " Started" );
:local routingTable "WAN1";
:local routingTable "WAN2";
@elico
elico / README.md
Last active June 1, 2024 18:13
Mikrotik RouterOS Lease script example
@elico
elico / filter-chr-rsc-for-import.rb
Created May 30, 2024 23:15
filter-chr-rsc-for-import.rb
#!/usr/bin/env ruby
def filter_text_file(input_file)
# Read the input file content
content = File.read(input_file)
# Split the content into lines
lines = content.split("\n")
# Initialize a variable to track if we are inside a block to remove
{
:do {
:local debug 1;
:local flagInterface "";
:local srcInterface "";
:local srcAddress "";
:set srcInterface "###INTERFACE_NAME###";
:set flagInterface "###FLAG_INTERFACE_NAME###";
@elico
elico / RouterOS-Detect-internet-connection.rsc
Last active April 10, 2024 22:09
A demo script to detect by url if a specific interface is up.
{
:do {
:local srcInterface1 "ether1-WAN1";
:local srcInterface2 "ether2-WAN2";
:local srcInterface3 "ether3-LTE";
:local srcInterface4 "pppoe-WAN1";
:local srcInterface5 "pppoe-WAN2";
:local srcInterface6 "pppoe-LTE1";
:local flagInterface "";
@elico
elico / backup-by-email.rsc
Last active March 26, 2024 21:50
RouterOS v7 hardware appliance email backup script
{
:do {
:log info "STARTING BACKUP process";
:local customerNumber "Ac3_Cust.no_1";
:local boardSerial [/system/routerboard/get serial-number];
:local sendMail true;
:local uploadFile false;
:local mailServer "smtp.gmail.com";
:local endpoint www.example.com;
:local wireguardInterface wireguard3;
:local wireguardInterfacePort [/interface/wireguard/get $wireguardInterface listen-port];
:foreach i in=[/interface/wireguard/peers/find where disabled=no endpoint-address=$endpoint] do={
:local LastHandshake [/interface/wireguard/peers/get $i last-handshake];
:if (([:tostr $LastHandshake] = "") or ($LastHandshake > [:totime "5m"])) do={
/interface/wireguard/set 0 listen-port=$wireguardInterfacePort name=$wireguardInterface;
:log warning "fixed wireguard";