Total Noob BASH scripting question


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Total Noob BASH scripting question
# 8  
Old 04-04-2018
Please start using code tags - refer to this
This User Gave Thanks to vgersh99 For This Post:
# 9  
Old 04-04-2018
Here's the output as it happens:

Code:
OS:Windows7Professional7601ServicePack1(Windows7Professional6.1)
FQDN:SD10.ssi.private

Starting Nmap 7.60 (  ) at 2018-04-04 16:39 CDT
Nmap scan report for sd10.ssi.private (10.0.0.13)
Host is up (0.86s latency).

PORT     STATE  SERVICE
21/tcp   closed ftp
22/tcp   closed ssh
23/tcp   closed telnet
25/tcp   closed smtp
53/tcp   closed domain
80/tcp   closed http
110/tcp  open   pop3
111/tcp  closed rpcbind
135/tcp  open   msrpc
139/tcp  closed netbios-ssn
143/tcp  open   imap
443/tcp  closed https
445/tcp  open   microsoft-ds
993/tcp  open   imaps
995/tcp  open   pop3s
1723/tcp closed pptp
3306/tcp closed mysql
3389/tcp closed ms-wbt-server
5900/tcp closed vnc
8080/tcp closed http-proxy

Nmap done: 1 IP address (1 host up) scanned in 2.43 seconds

Starting Nmap 7.60 (  ) at 2018-04-04 16:39 CDT
Nmap scan report for 10.0.0.16
Host is up (0.0046s latency).

PORT     STATE    SERVICE
21/tcp   filtered ftp
22/tcp   open     ssh
23/tcp   filtered telnet
25/tcp   filtered smtp
53/tcp   filtered domain
80/tcp   filtered http
110/tcp  open     pop3
111/tcp  filtered rpcbind
135/tcp  filtered msrpc
139/tcp  filtered netbios-ssn
143/tcp  open     imap
443/tcp  filtered https
445/tcp  filtered microsoft-ds
993/tcp  open     imaps
995/tcp  open     pop3s
1723/tcp filtered pptp
3306/tcp filtered mysql
3389/tcp filtered ms-wbt-server
5900/tcp filtered vnc
8080/tcp filtered http-proxy

Nmap done: 1 IP address (1 host up) scanned in 1.64 seconds

Starting Nmap 7.60 ( ) at 2018-04-04 16:39 CDT
Nmap scan report for sdl03.ssi.private (10.0.0.22)
Host is up (0.86s latency).

PORT     STATE  SERVICE
21/tcp   closed ftp
22/tcp   closed ssh
23/tcp   closed telnet
25/tcp   closed smtp
53/tcp   closed domain
80/tcp   closed http
110/tcp  open   pop3
111/tcp  closed rpcbind
135/tcp  open   msrpc
139/tcp  closed netbios-ssn
143/tcp  open   imap
443/tcp  closed https
445/tcp  open   microsoft-ds
993/tcp  open   imaps
995/tcp  open   pop3s
1723/tcp closed pptp
3306/tcp closed mysql
3389/tcp closed ms-wbt-server
5900/tcp closed vnc
8080/tcp closed http-proxy

Nmap done: 1 IP address (1 host up) scanned in 2.43 seconds

---------- Post updated at 04:45 PM ---------- Previous update was at 04:44 PM ----------

Sorry about the code tags thing...will do....total noob to the board too!

Last edited by vgersh99; 04-04-2018 at 06:54 PM..
# 10  
Old 04-04-2018
could run the script below and provide output using code tags!
Code:
#!/bin/bash

DISCOVERY ()
{
   addr="${1}"
   echo "DISCOVERY [${addr}]"
}
PORTS ()
{
  addr="${1}"
  echo "  PORTS [${addr}]"
}

while read address junk
do
   DISCOVERY "${address}"
   PORTS "${address}"
done < activeips.txt

---------- Post updated at 05:53 PM ---------- Previous update was at 05:46 PM ----------

Quote:
Originally Posted by Dirk_Pitt
Here's the output as it happens:

OS:Windows7Professional7601ServicePack1(Windows7Professional6.1)
FQDN:SD10.ssi.private

Starting Nmap 7.60 ( ) at 2018-04-04 16:39 CDT
Nmap scan report for sd10.ssi.private (10.0.0.13)
Host is up (0.86s latency).

PORT STATE SERVICE
21/tcp closed ftp
22/tcp closed ssh
23/tcp closed telnet
25/tcp closed smtp
53/tcp closed domain
80/tcp closed http
110/tcp open pop3
111/tcp closed rpcbind
135/tcp open msrpc
139/tcp closed netbios-ssn
143/tcp open imap
443/tcp closed https
445/tcp open microsoft-ds
993/tcp open imaps
995/tcp open pop3s
1723/tcp closed pptp
3306/tcp closed mysql
3389/tcp closed ms-wbt-server
5900/tcp closed vnc
8080/tcp closed http-proxy

Nmap done: 1 IP address (1 host up) scanned in 2.43 seconds

Starting Nmap 7.60 ( ) at 2018-04-04 16:39 CDT
Nmap scan report for 10.0.0.16
Host is up (0.0046s latency).

PORT STATE SERVICE
21/tcp filtered ftp
22/tcp open ssh
23/tcp filtered telnet
25/tcp filtered smtp
53/tcp filtered domain
80/tcp filtered http
110/tcp open pop3
111/tcp filtered rpcbind
135/tcp filtered msrpc
139/tcp filtered netbios-ssn
143/tcp open imap
443/tcp filtered https
445/tcp filtered microsoft-ds
993/tcp open imaps
995/tcp open pop3s
1723/tcp filtered pptp
3306/tcp filtered mysql
3389/tcp filtered ms-wbt-server
5900/tcp filtered vnc
8080/tcp filtered http-proxy

Nmap done: 1 IP address (1 host up) scanned in 1.64 seconds

Starting Nmap 7.60 ( ) at 2018-04-04 16:39 CDT
Nmap scan report for sdl03.ssi.private (10.0.0.22)
Host is up (0.86s latency).

PORT STATE SERVICE
21/tcp closed ftp
22/tcp closed ssh
23/tcp closed telnet
25/tcp closed smtp
53/tcp closed domain
80/tcp closed http
110/tcp open pop3
111/tcp closed rpcbind
135/tcp open msrpc
139/tcp closed netbios-ssn
143/tcp open imap
443/tcp closed https
445/tcp open microsoft-ds
993/tcp open imaps
995/tcp open pop3s
1723/tcp closed pptp
3306/tcp closed mysql
3389/tcp closed ms-wbt-server
5900/tcp closed vnc
8080/tcp closed http-proxy

Nmap done: 1 IP address (1 host up) scanned in 2.43 seconds

---------- Post updated at 04:45 PM ---------- Previous update was at 04:44 PM ----------

Sorry about the code tags thing...will do....total noob to the board too!
I don't see anything wrong with this output
your DISCOVERY for 1st address:
Code:
Starting Nmap 7.60 ( ) at 2018-04-04 16:39 CDT
Nmap scan report for sd10.ssi.private (10.0.0.13)
Host is up (0.86s latency).

your PORTS for 1st address:
Code:
PORT STATE SERVICE
21/tcp closed ftp
22/tcp closed ssh
23/tcp closed telnet
25/tcp closed smtp
53/tcp closed domain
80/tcp closed http
110/tcp open pop3
111/tcp closed rpcbind
135/tcp open msrpc
139/tcp closed netbios-ssn
143/tcp open imap
443/tcp closed https
445/tcp open microsoft-ds
993/tcp open imaps
995/tcp open pop3s
1723/tcp closed pptp
3306/tcp closed mysql
3389/tcp closed ms-wbt-server
5900/tcp closed vnc
8080/tcp closed http-proxy

and so on....
# 11  
Old 04-04-2018
Here ya go....this is the part that doesn't make sense....

In this output...for your test script....it LOOKS like they run back and forth

Code:
DISCOVERY [10.0.0.13]
  PORTS [10.0.0.13]
DISCOVERY [10.0.0.16]
  PORTS [10.0.0.16]
DISCOVERY [10.0.0.22]
  PORTS [10.0.0.22]
DISCOVERY [10.0.0.17]
  PORTS [10.0.0.17]
DISCOVERY [10.0.0.19]
  PORTS [10.0.0.19]
DISCOVERY [10.0.0.20]
  PORTS [10.0.0.20]
DISCOVERY [10.0.0.12]
  PORTS [10.0.0.12]
DISCOVERY [10.0.0.11]
  PORTS [10.0.0.11]
DISCOVERY [10.0.0.15]
  PORTS [10.0.0.15]
DISCOVERY [10.0.0.24]
  PORTS [10.0.0.24]
DISCOVERY [10.0.0.63]
  PORTS [10.0.0.63]
DISCOVERY [10.0.0.62]
  PORTS [10.0.0.62]
DISCOVERY [10.0.0.80]
  PORTS [10.0.0.80]

But...as we run the actual nmap commands, I'm thinking that since the first one doesn't finish it as quick as the second one does, the second one just jumps to the next address and the next and the next. Maybe the syntax is all right, but we need a way to tell PORTS to wait for DISCOVERY to finish before they continue on to the next ip?
# 12  
Old 04-04-2018
everything makes sense.DISCOVERY runs first - then PORTS runs one address at a time.
Your real script is a bit noisy in the output, but it produces output in the expected order.

To illustrate, here's your script with steps:
Code:
#!/bin/bash

DISCOVERY ()
{
   addr="${1}"
   echo "DISCOVERY [${addr}]"
   nmap -v -p 139,445 --script=smb-os-discovery "${addr}" |grep -v 'smb-os-discovery' | grep -v 'OS CPE' | grep -v 'Computer name' | grep -v 'NetBI'
}
PORTS ()
{
  addr="${1}"
  echo "   PORTS [${addr}]"
  nmap -sT --top-ports 20 "${addr}"
}

while read address junk
do
   DISCOVERY "${address}"
   PORTS "${address}"
done < activeips.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Noob question: How to check the total number of inputs entered by user?

Say I have this line: read -p "Enter 3 numbers: " num1 num2 num3; I want to write a while loop that repeatedly asks for input if the number of inputs entered is not equal to 3. I don't know the correct command to find the number of inputs entered. Help, please? (4 Replies)
Discussion started by: jejemonx
4 Replies

2. Shell Programming and Scripting

Noob to scripting needs some assistance

Hello, I am in a Unix class and have been out of town. I have been tasked to generate a couple of scripts and ahve never done it before. I have a virtual machine running Ubuntu. The task is below Prompt the system administrator for all valid input parameters Generate a menu to ask which... (1 Reply)
Discussion started by: jkeeton81
1 Replies

3. Shell Programming and Scripting

Beginner Bash Scripting Question

Hello, I am new to Linux and studying to become a Unix System Admin. I am taking a course in which I was practicing creating a bash script to ping a particular IP address. The script can be found below: #/bin/bash echo "Enter the IP address" read ip if then ping -c 1 $ip if ;... (3 Replies)
Discussion started by: shah9250
3 Replies

4. Shell Programming and Scripting

Noob Expect Scripting Question

I'm having some difficulty with convincing Expect to do what I need.. I have a loop that waits for input, a specific phrase of text followed by a single word. I need Expect to capture that word following the specific phrase. It should then store the word in a variable. I'm fairly sure it's... (6 Replies)
Discussion started by: LongLeafTea
6 Replies

5. Shell Programming and Scripting

Bash scripting question

have a script that calls child scripts depending on conditions. All of the child scripts source in a common file that contains shared functions. At the moment each script has to source this file itself, is there a way for the master script to automagically source the file for them? For... (3 Replies)
Discussion started by: redman
3 Replies

6. Shell Programming and Scripting

Noob to Shell Scripting

Hello. I'm attempting to create a shell script to assist me by saving time with one of my hobbies. I am an Android Enthusiast and currently build a few roms for one of the devices. One of the roms I make is ported from a different device to mine (I get the original for the HTC Desire HD and... (3 Replies)
Discussion started by: JHutson456
3 Replies

7. UNIX for Dummies Questions & Answers

Noob scripting question with android ADB commands

Hi I'm pretty new to scripting and I've been googling around looking for an answer but have yet to come up with a proper solution. I work with multiple android devices at a time and I'm looking to simplify my life with a script. Basically I'm looking for a script that takes the device ID's and then... (2 Replies)
Discussion started by: Onyoursix
2 Replies

8. Shell Programming and Scripting

Total noob script

Hi i am a total noob at shell scripting. i was wondering if somebody could help me with my script. i want the script to search the dev folder for the burner file because they are different between distrubutions? as i under stand it. this i the script. #!/bin/bash echo "Script för att bränna 360... (4 Replies)
Discussion started by: MatsO
4 Replies

9. Shell Programming and Scripting

Bash scripting, question about a variable

Hey, So I've run into a problem, due to my limited knowledge of Bash scripting. Basically I've got a long script and I want to understand it before I even try and edit it. As long as I don't understand the script, I will not bother editing it. Anyway, the following variable confuses me... (5 Replies)
Discussion started by: abciscool
5 Replies

10. Shell Programming and Scripting

Bash scripting question re: newlines

I'm writing a bash script to search the contents of a postfix log. To keep the script's output readable (since multiple lines from the log file need to be echo'ed) I am setting the IFS variable to an empty string so that the line breaks in my grep results are preserved. I am storing the results... (4 Replies)
Discussion started by: retrovertigo
4 Replies
Login or Register to Ask a Question