LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-26-2015, 01:05 PM   #1
floriankunushevci
LQ Newbie
 
Registered: Jun 2015
Posts: 8

Rep: Reputation: Disabled
Question Nmap problem in BASH - Anyone who could help me ?


Hi, i'am a new newbie in linux, i need a help in Bash Scripting, in nmap, i cant exectue an IP i want, on this script, it execute 0.0.0.0 and it says :
setup_target: failed to determine route to 0.0.0.....

Thank you, if anyone could help me.

Script is this :
#!/bin/bash
echo "Type 1 to go PortScan"
read aaa
if [ $aaa = "1" ]
then
echo "Type IP"
read nmapp
nmap $?/22 $nmapp
fi
 
Old 06-26-2015, 03:11 PM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
I'm not sure what you think this line is supposed to do:
[CODE]nmap $?/22 $nmapp[\CODE]

If your intent is to check port 22 on the IP provided the line should be:
[CODE]nmap -p 22 $nmapp[\CODE]

$? means the return code from the previous command which would be zero (0) if successful. Your use of $? therefore is saying check IP 0 which expands to 0.0.0.0 which is why you see the errors.

If you run "man nmap" you can see documentation for the way to use this command.
 
Old 06-26-2015, 04:14 PM   #3
floriankunushevci
LQ Newbie
 
Registered: Jun 2015
Posts: 8

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by MensaWater View Post
I'm not sure what you think this line is supposed to do:
[CODE]nmap $?/22 $nmapp[\CODE]

If your intent is to check port 22 on the IP provided the line should be:
[CODE]nmap -p 22 $nmapp[\CODE]

$? means the return code from the previous command which would be zero (0) if successful. Your use of $? therefore is saying check IP 0 which expands to 0.0.0.0 which is why you see the errors.

If you run "man nmap" you can see documentation for the way to use this command.
Well u helped me alot with that -p but i want to listen all ports on example 127.0.0.* there, do u understand, if u can help me beacuse that -p helped me alot. Thank you, if u have anyidea please reply
 
Old 06-26-2015, 04:29 PM   #4
joe_2000
Senior Member
 
Registered: Jul 2012
Location: Aachen, Germany
Distribution: Void, Debian
Posts: 1,016

Rep: Reputation: 308Reputation: 308Reputation: 308Reputation: 308
Quote:
Originally Posted by floriankunushevci View Post
Well u helped me alot with that -p but i want to listen all ports on example 127.0.0.* there, do u understand, if u can help me beacuse that -p helped me alot. Thank you, if u have anyidea please reply
Just leave out the -p. It will then scan all ports. If you want to scan an ip range, you can specify it like so:

Code:
nmap 127.0.0.1-255
(although this ip range does not really make a lot of sense).
Alternatively, you can also use the netmask like so:

Code:
nmap 127.0.0.1/24
On a separate note please spell out your words completely / avoid using text message speak. This is considered impolite in this forum.
 
Old 06-26-2015, 05:09 PM   #5
floriankunushevci
LQ Newbie
 
Registered: Jun 2015
Posts: 8

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by joe_2000 View Post
Just leave out the -p. It will then scan all ports. If you want to scan an ip range, you can specify it like so:

Code:
nmap 127.0.0.1-255
(although this ip range does not really make a lot of sense).
Alternatively, you can also use the netmask like so:

Code:
nmap 127.0.0.1/24
On a separate note please spell out your words completely / avoid using text message speak. This is considered impolite in this forum.
Yeah i try with script but it dosnt work, to scan all ports on that range, i dont know why
#!/bin/bash
echo "Shtypni 1 per te vazhduar NMAP"
read file
if [ $file = "1" ]
then
echo "[+]Shtyp IP[+]"
read nmapp
nmap /24 $nmapp
echo "[+]Scanimi perfundoi[+]"
fi
 
Old 06-26-2015, 06:11 PM   #6
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Code:
#!/bin/bash
# LQRocks!
echo "Type 1 to go PortScan"
read SCAN_YES
if [ $SAN_YES = 1 ]; then
    echo "Type IP"
    read IP
    nmap "$IP" -p 22
else
    exit
fi
It's easier to code and debug if you have variables that actually mean something.
Leave off the "-p 22" if you want to scan for all ports on "$IP"

Last edited by Habitual; 06-29-2015 at 07:03 AM. Reason: modidied answer variable to SCAN_YES
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
-bash: nmap: command not found v@ny@ Linux - Software 7 01-27-2019 11:16 AM
[SOLVED] nmap problem validator456 Linux - Networking 5 07-06-2014 12:23 AM
nmap ? how do i do nmap in linux ? command not found abbasakhtar Linux - Newbie 2 01-02-2011 01:08 AM
LXer: Learn how to use nmap, and nmap GUI, a great port scan tool LXer Syndicated Linux News 0 01-03-2008 09:10 AM
nmap increase send delay for nmap 4.20 matters Slackware 1 10-01-2007 11:37 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:18 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration