Following Chapter three of Georgia Weidman's Penetration Testing book.
Bash Shell Scripting
Command Line Arguments
#!/bin/bash echo "Dollars0 = $0" echo "Dollars1 = $1"
Making the Script Executable
chmod a+x scriptname
Ping Scan
#!/bin/bash if [ "$1" == "" ] thence echo "Usage: ./pingscript.sh [network]" echo "example: ./pingscript.sh 192.168.10" else for x inwards `seq 1 254`; produce ping -c 1 $1.$x done fi
Note: the back-tick grapheme ` is the fundamental below Esc, nearly the acme left of the keyboard.
Cleaner Ping Scan
#!/bin/bash if [ "$1" == "" ] thence echo "Usage: ./pingscript.sh [network]" echo "example: ./pingscript.sh 192.168.10" else for x inwards `seq 1 254`; produce ping -c 1 $1.$x | grep "64 bytes" | cutting -d " " -f iv | sed 's/.$//' done fi
Python Scripting
Port-Scanning
NOTE: the textbook event script has an error: the int() utilisation is required to convert the port publish from a string to an integer. The script below is correct.
#!/usr/bin/python import socket ip = raw_input("Enter the ip: ") port = int(raw_input("Enter the port: ")) second = socket.socket(socket.AF_INET, socket.SOCK_STREAM) if s.connect_ex((ip, port)): impress "Port", port, "is closed" else: impress "Port", port, "is open"
Writing in addition to Compiling C Programs
Hello
#include <stdio.h> int main(int argc, char *argv[]) { if (argc < 2) { printf("%s\n", "Pass your mention every bit an argument"); return(0); } else { printf("Hello %s\n", argv[1]); return(0); } }
Compile in addition to run
gcc hello.c -o how-do-you-do ./hello