2

I have an nmap output looking like this

Nmap scan report for 10.90.108.82
Host is up (0.16s latency).

PORT   STATE SERVICE
80/tcp open  http
|_http-title: Did not follow redirect to https://10.90.108.82/view/login.html

I would like the output to be like

10.90.108.82 http-title: Did not follow redirect to https://10.90.108.82/view/login.html

How can it be done using grep or any other means?

Cœur
  • 37,241
  • 25
  • 195
  • 267
eric
  • 21
  • 1
  • **Try writing something yourself** and then if it doesn't work, show us specifically what you did so we can help you along. You start it, and then we help. We don't write it for you. Show us the actual code that you've tried, and then describe what happened and what's not right, and then we can help you from there. Chances are you'll get pretty close to the answer if you just try it yourself first. – Andy Lester Jun 09 '21 at 14:25

3 Answers3

0

You can use the following nmap.sh script like that:

<nmap_command> | ./nmap.sh

nmap.sh:

#!/usr/bin/env sh

var="$(cat /dev/stdin)"
file=$(mktemp)
echo "$var" > "$file"

ip_address=$(head -1 "$file" | rev | cut -d ' ' -f1 | rev)
last_line=$(tail -1 "$file" | sed -E "s,^\|_, ,")

printf "%s%s\n" "$ip_address" "$last_line"
rm "$file"
Arkadiusz Drabczyk
  • 11,227
  • 2
  • 25
  • 38
  • hi,i tried your script but it wasnot working.the full command is : sudo nmap -n -p 80 -Pn --script http-title 31.13.92.0-200 |./nmap.sh .The error i get is : CETNmap done: 201 IP addresses (201 hosts up) scanned in 22.94 seconds – eric Nov 09 '18 at 06:08
0

If you do not mind using a programming language, check out this code snippet with Python:

import nmapthon as nm

scanner = nm.NmapScanner('10.90.108.82', ports=[80], arguments='-sS -sV --script http-title')
scanner.run()

if '10.90.108.82' in scanner.scanned_hosts(): # Check if host responded
    serv = scanner.service('10.90.108.82', 'tcp', 80)
    if serv is not None: # Check if service was identified
        print(serv['http-title'])

Do not forget to execute pip3 install nmapthon.

I am the author of the library, feel free to have a look here

Cblopez
  • 446
  • 2
  • 12
-2

Looks like you want an [nmap scan] output to be edited and displayed as you wish. Try bash scripting, code a bash script and run it.

Here's an link to a video where you might find an answer to your problem: https://youtu.be/lZAoFs75_cs

Watch the video from the Time Stamp 1:27:17 where the creator briefly describes how to cut-short an output and display it as we wish. If you require, I could code an bash script to execute an cut-shorted version of the output given by an nmap scan.

Dominique
  • 16,450
  • 15
  • 56
  • 112
an33sh
  • 32
  • 5
  • Welcome to Stackoverflow. Please remember not to only link to third party websites and/or videos, since these might disappear in the future and this answer will then be rendered mood. – jhoepken Jun 08 '21 at 12:33