Skip to content

Instantly share code, notes, and snippets.

@maciakl
maciakl / cleanup.cmd
Created January 13, 2022 15:59
Script to clean up your Downloads directory by deleting all files and folders older than 14 days
@echo off
REM Remove files older than 14 days
forfiles /p "C:\Users\lmaciak\Downloads" /s /m *.* /c "cmd /c Del @path" /d -14
forfiles /p "C:\Users\lmaciak\Downloads" /s /d -14 /c "cmd /c if @isdir == TRUE RMDIR /S /Q @path"
@maciakl
maciakl / servicetag.cmd
Created January 13, 2022 15:56
Get the service tag (Dell) or vendor assigned serial number of your computer. This returns just the number, without other wmic output.
@echo off
for /f "skip=1" %%a in (
'wmic bios get serialnumber'
) do echo %%a & goto next
:next
@maciakl
maciakl / localip.cmd
Created January 13, 2022 15:55
Get you local ip address from the Windows command line
@echo off
for /f "delims=[] tokens=2" %%a in ('ping -4 -n 1 %ComputerName% ^| findstr [') do set NetworkIP=%%a
echo %NetworkIP%
@maciakl
maciakl / whatismyip.cmd
Created January 13, 2022 15:54
Get your public/routable ip address from the windows command line
@echo off
for /f "tokens=1* delims=: " %%A in (
'nslookup myip.opendns.com. resolver1.opendns.com 2^>NUL^|find "Address:"'
) Do set ExtIP=%%B
echo %ExtIP%
@maciakl
maciakl / python_same_window_fix.cmd
Created January 10, 2022 21:27
This fixes the issue on Windows where running Python script directly by invoking its name (eg. script.py) on the command line, launches a new console window, instead of showitg the output in the same console.
rem Run CMD.EXE as Admin, then
assoc .py=Python.File
rem Assuming you installed Python via the Microsoft use below
rem If yuou installed Python via an installer, substitute the absolute path to the python executable
ftype Python.File=%LOCALAPPDATA%\Microsoft\WindowsApps\python.exe "%1" %*
@maciakl
maciakl / elevate.cmd
Last active January 8, 2024 00:11
If your batch file needs to run as Administrator, put this at the top of your script. It will initiate a UAC prompt and run the rest of the script in elevated mode.
if "%1" == "elevated" goto start
powershell -command "Start-Process %~nx0 elevated -Verb runas"
goto :EOF
:start
rem your code goes here
#!/bin/bash
# This script defines environment variables which allow you to
# easily colorize your scripts.
#
# At the start of your bash script simply source this file like this:
#
# [ -f "$HOME/scripts/colors" ] && source $HOME/scripts/colors
#
# Then you can use all the variables to colorize output like this:
@maciakl
maciakl / makeafile
Last active June 21, 2019 14:13
Make a file of a specific size
#!/bin/bash
die() {
echo>&2 " Usage: makefile <filename> <size>"
echo>&2 " size is in format <number><unit> where unit can be K,M,G, etc... Example: 256K, 10M, 1G."
exit 1
}
[ "$#" -eq 2 ] || die
dd if=/dev/urandom of=$1 bs=$2 count=1
@maciakl
maciakl / tunnel-create
Last active June 21, 2019 14:05
Scripts for SSH Tunneling
#!/bin/bash
# Script to tunnel to a remote server from a firewall using a third
# server in the middle.
[ -f "$HOME/scripts/colors" ] && source $HOME/scripts/colors
USAGE="USAGE:\n\t tunnel-create $Color_Blue BOUNCE_SERVER DESTINATION$COlor_Off $Color_Cyan[BOUNCE_PORT] [DEST_PORT]$Color_Off\n\n"
USAGE+="\t $Color_Blue BOUNCE_SERVER$Color_Off\t - Server through which you will be tunneling\n"
USAGE+="\t $Color_Blue DESTINATION$Color_Off\t - Server you want to ssh into.\n"
@maciakl
maciakl / index.html
Created June 3, 2019 20:33
Very basic status monitoring page for your local network.
<!doctype html>
<html>
<head>
<title>System Status</title>
<style>
body {
margin-top: 50px;
margin-left: 25%;
margin-right: 25%;