# Scripting

{% embed url="<https://tldp.org/LDP/abs/html/special-chars.html>" %}

{% hint style="info" %}
ALWAYS put a space between the square brackets \[ and the contents! (etc if \["$1" == ""] will generate an error!)
{% endhint %}

## Enumeration

### ipsweep.sh

Pings ip address in the entire range to see who is up (etc ping 192.168.1.1 to 192.168.1.254) , greps 64 bytes line as its the linux default bytes for ping

```bash
#!/bin/bash

if [ "$1" == "" ]
then
echo "You forgot to input an IP address!"
echo "Syntax: ./ipsweep.sh <insert ip target>"

else
for ip in `seq 1 254`; do # seq a b will do a range(a,b+1)
ping -c 1 $1.$ip | grep "64 bytes" | cut -d " " -f 4 | tr -d ":" & # & allows the loop to be run all at once (254 sequences)       
done   # alternative is to put ; before done, which iterates 1 sequence at a time instead
fi
# $1 - takes user input "./ipsweep.sh <input the ip of ping target>

# INPUT should be excluding the last octet : etc 192.168.1 (last octet is looped)
```

<div align="left"><img src="https://2068334946-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fow1iM27u7disHeJiSlBC%2Fuploads%2Fgdw6ATUosFgBwBuKjhe5%2Fimage.png?alt=media&#x26;token=0220dea2-0420-455c-8307-dab8cedb734d" alt=""></div>

Need trick is to use nmap loop on output text of IP results from this script

```
>>>in your kali terminal 
 for ip in $(cat iplist.txt); do nmap -p 80 -T4 $ip & done
 # -T4 is the scanning speed
 # & makes it run all at once, ; makes it run once at a time
```

The speed template nmap -T4 flag ranges from 0 for slow and stealthy to 5 for fast and obvious.25

![Sample results ](https://2068334946-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fow1iM27u7disHeJiSlBC%2Fuploads%2FaqOhmrYe3UYlAy12AQOs%2Fimage.png?alt=media\&token=6cc30f69-d497-4a4b-a5cb-0021e8c9f331)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://davin-hong3.gitbook.io/d/walkthroughs/cybersecurity-concepts/scripting.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
