Unix/Linux Go Back    


Programming Post questions about C, C++, Java, SQL, and other programming languages here.

Nmap shell script goes in infinite loop

Programming


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 05-25-2017   -   Original Discussion by sk151993
sk151993's Unix or Linux Image
sk151993 sk151993 is offline
Registered User
 
Join Date: Mar 2017
Last Activity: 24 July 2017, 12:36 PM EDT
Posts: 15
Thanks: 1
Thanked 0 Times in 0 Posts
Nmap shell script goes in infinite loop

My script’s output goes in infinite loop

Below is my script:


Code:
Nmap()
{
while read -r line
do
name="$line"
echo "$name"
count=$line

nmap -oG output.txt -T4 -f -iL iplist.txt $line1
done < iplist.txt
}
Nmap

.................................................................

IPlist.txt contain so many ip’s. Whatever user is added ip’s in file, all ip’s are read one by one.

Problem:
This ip scan is goes in infinite loop.

Below source code contain problem:


Code:
while read -r line
do
name="$line"
echo "$name"
count=$line

nmap -oG output.txt -T4 -f -iL iplist.txt $line1
done < iplist.txt

How should I fix this? Please suggest.

Last edited by sk151993; 06-01-2017 at 02:54 AM..
Sponsored Links
    #2  
Old Unix and Linux 05-25-2017   -   Original Discussion by sk151993
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is offline Forum Staff  
Administrator
 
Join Date: Jul 2012
Last Activity: 17 December 2017, 3:04 AM EST
Location: San Jose, CA, USA
Posts: 10,790
Thanks: 592
Thanked 3,772 Times in 3,220 Posts
With your code:

Code:
while read -r line
do
name="$line"
echo "$name"
count=$line

nmap -oG output.txt -T4 -f -iL iplist.txt $line1
done < iplist.txt

you have three names for the contents of a line from iplist.txt: line, name, and count. But in your invocation of nmap you use $line1. Since line1 has not been defined in your script anywhere, that will expand to an empty string unless line1 is an exported variable in your environment.

I don't have nmap on my system. The Linux nmap man page isn't clear about what servers(s) it attempts to scan if no targets are given on the command line. Maybe it seems like an infinite loop because you are trying to scan every server on the internet???
Sponsored Links
    #3  
Old Unix and Linux 05-25-2017   -   Original Discussion by sk151993
Aia's Unix or Linux Image
Aia Aia is offline
Registered User
 
Join Date: May 2008
Last Activity: 20 November 2017, 9:27 AM EST
Posts: 1,673
Thanks: 49
Thanked 641 Times in 601 Posts
Quote:
Originally Posted by Don Cragun View Post
With your code:

Code:
while read -r line
do
name="$line"
echo "$name"
count=$line

nmap -oG output.txt -T4 -f -iL iplist.txt $line1
done < iplist.txt

you have three names for the contents of a line from iplist.txt: line, name, and count. But in your invocation of nmap you use $line1. Since line1 has not been defined in your script anywhere, that will expand to an empty string unless line1 is an exported variable in your environment.

I don't have nmap on my system. The Linux nmap man page isn't clear about what servers(s) it attempts to scan if no targets are given on the command line. Maybe it seems like an infinite loop because you are trying to scan every server on the internet???
If no target is given, nmap just exists, telling you that 0 target has been scanned.

-iL iplist.txt That's the target, a list of possible IPs if the filename is an indication.
It is not running in an infinite loop. It is running that list on each iteration of the loop.

Try that one.

Code:
while read -r line
do
echo "$line"
nmap -oG output.txt -T4 -f  $line
done < iplist.txt

or just

Code:
nmap -oG output.txt -T4 -f -iL iplist.txt

The Following User Says Thank You to Aia For This Useful Post:
sk151993 (06-01-2017)
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Calling a script from a shell that needs to cancel out of infinite loop guessingo Shell Programming and Scripting 1 04-26-2016 04:46 PM
Infinite while loop script shows more than one process chetan.c Shell Programming and Scripting 4 06-22-2012 06:59 AM
Script with infinite loop stops after sometime pkabali Shell Programming and Scripting 3 04-08-2011 08:15 AM
Script to run infinite loop digitalrg Shell Programming and Scripting 1 04-15-2009 01:23 PM
Running a script in INFINITE LOOP Raamc Shell Programming and Scripting 5 10-21-2008 01:23 PM



All times are GMT -4. The time now is 07:51 AM.