Scripting in Mikrotiks can be a little interesting. This is a quick syntax note for using the foreach command to delete all simple queues.
:foreach queue in=[/queue/simple/find ] do={/queue/simple/remove $queue}
Scripting in Mikrotiks can be a little interesting. This is a quick syntax note for using the foreach command to delete all simple queues.
:foreach queue in=[/queue/simple/find ] do={/queue/simple/remove $queue}
You can earn Microsoft rewards by using Bing for searching. What if you could automate Bing searches to automatically get rewards? Oh wait. PowerShell can launch Edge with a Bing search! So we can acquire Microsoft Rewards with PowerShell!
Create a new PowerShell file and past the following in.
1..30 | ForEach-Object{Start-Process msedge https://www.bing.com/search?q=bing+$_ Start-Sleep -Milliseconds 3000 }
The script will launch 30 Edge tabs with a Bing search of “Bing 1” next tab will be “Bing 2” etc. You could definitely be more creative with what and how you search for things, but this works as a proof of concept.
I created and ran this script from Visual Studio Code. But you should be able to create it with a normal text file and launch it in PowerShell.
The person at the following link did an excellent job at creating a system for this. Looks really cool.
Move all the VLANs under ether7 to ether6. Instead of an “=” sign, you can use a “~” to do a partial match.
foreach i in=[/interface vlan find where interface="ether7"] do={interface vlan set interface=ether6-master-local $i }
Move ip address from ether6 to ether7. Change 192.168.88.1/24 to the address and the find command will find it regardless of the port and assign it to ether6 or whichever port is specified.
ip address set interface=ether6-master-local [find address="192.168.88.1/24"]
You can add a delay before a command runs by specifying delay and then the time to wait.
delay 60
Use the ; to separate commands. Example below, wait 5 seconds then print the ip addresses.
delay 5 ; ip address print
The following command/s will wait 60 seconds then move all the VLANs on ether7 to ether6 and then move the 192.168.88.1/24 address to ether6.
delay 60 ; foreach i in=[/interface vlan find where interface="ether7"] do={interface vlan set interface=ether6-master-local $i } ; ip address set interface=ether6-master-local [find address="192.168.88.1/24"]
Basically count to 100 and perform an operation each time i increases.
for ((i=1; i<=100;i++)) do echo $i done
for loop 1 liner
for ((i=1; i<=100;i++)) do echo $i ; done
Handy if you just want a script to run and repeat the same thing over and over again. Doesn't stop till you kill it.
while true do echo "Repeat till infinity" sleep 1 done
The following will execute the loop as long as the command in the () returns true. Once it returns false, it'll stop the loop
while (fping incredigeek.com | grep alive); do echo alive sleep 1 done
#!/bin/bash array=(one two three) echo "Printing first object in array." #Replace 0 with the place number of the array item echo ${array[0]} echo "" echo "Whole array" echo ${array[*]} echo "" echo "Array indexes" echo ${!array[*]}
Output
Printing first object in array. one Whole array one two three Array indexes 0 1 2
Create a file “list.txt” that contains all the URLs you want to download and launch the following command
for i in cat list.txt
; do wget ${i} && sleep $(( ( RANDOM % 120 ) +1 )) ; done
It’ll now run and after each link will wait a random amount of time up to 120 seconds before downloading the next link. Change the number as needed.
As a side note there is a lot of good bash info out here. https://www.gnu.org/software/bash/manual/bashref.html
3.1.2.4 ANSI-C Quoting
Words of the form $'string'
are treated specially. The
word expands to string, with backslash-escaped characters replaced
as specified by the ANSI C standard. Backslash escape sequences, if
present, are decoded as follows:
\a
alert (bell)
\b
backspace
\e
\E
an escape character (not ANSI C)
\f
form feed
\n
newline
\r
carriage return
\t
horizontal tab
\v
vertical tab
\\
backslash
\'
single quote
\"
double quote
\?
question mark \nnn
Some examples
echo Hello $'\t' World
Returns “Hello World” with a tab space between both words.
echo Hello $'\n' World
Returns Hello on one line and World on the second
echo "\"Hello World\""
Returns “Hello World” inside double quotes
This script adds a new SFTP user with only sftp access. Refer to this post on setting up a SFTP server.
Download script
wget www.incredigeek.com/home/downloads/scripts/sftpUserAdd.sh
Make executable
chmod +x sftpUserAdd.sh
Run with the new user you want to create.
./sftpUserAdd.sh sftpUsername
You may need to edit the script and modify the location parameters.
#!/bin/bash
# Automatically setup and add SFTP user
# Script creates new user and setups permissions
newUser=$1
sftpDir="/sftp/"
if grep -q ${newUser} /etc/passwd ;then
echo ${newUser} Already exsists. Aborting!
exit 1
else
mkdir -p ${sftpDir}/${newUser}/files
useradd -g sftpusers -d ${sftpDir}/${newUser}/files -s /sbin/nologin ${newUser}
passwd ${newUser}
chown ${newUser}:sftpusers /sftp/CareMark/files
fi
Copy and paste the following into a file named mtbypass.sh and then “chmod +x mtbypass.sh” Or download from this direct link. Be sure to change the username and password
#!bin/bash filelist="bypasslist.txt" username="admin" password="password!" ip="$1" for i in `cat ${filelist}` do address=`echo $i | cut -d= -f1` mac=`echo $i | cut -d= -f2` sshpass -p ${password} ssh ${username}@${ip} "ip hotspot ip-binding add address=${address} mac-address=${mac} type=bypassed" done
Now create a file named bypasslist.txt and put all the addresses you want bypassed. You’ll need the Mac Address and the IP Address.
Example file
192.168.88.2=4C:5E:0C:B8:4E:01 192.168.88.3=3E:AA:A1:2D:8B:2C 192.168.88.5=DE:D1:39:65:91:4E
Usage of script is
./mtbypass.sh MikrotikIP
Example:
./mtbypass.sh 192.168.88.1
You’ll need a touch screen to test this out. Easiest way is to use the Unity Remote 5 app. It allows you to use your Android device as a touch screen input.
Start by creating a new empty C# script named “TouchScript” and paste in the following code.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TouchScript : MonoBehaviour {
public GameObject bullet;
void Start () {
}
void Update () {
Touch myTouch = Input.GetTouch (0);
for(int i =0; i < Input.touchCount; i++)
if (myTouch.phase == TouchPhase.Began) {
{
Debug.Log ("Touch Position" + myTouch.position);
SpawnBullet (myTouch);
}
}
}
void SpawnBullet(Touch fireTouch) {
Vector3 touchPos = Camera.main.ScreenToWorldPoint (fireTouch.position);
touchPos.z = 1; // Puts the z coordinates at 1 so it is visible to the camera.
Debug.Log("Vector3 Pos" + touchPos);
Instantiate (bullet, touchPos, Quaternion.identity);
}
}
Now you’ll need to put your script on a game object. You should be able to drag and drop it on any game object, in this case the Main Camera “green”.
Next drag and drop the game object prefab to the script “red”. This tells the script which game object to spawn or instantiate when you touch the screen.
Run the scene. It should now create a game object where you touch on the screen.