I write a script to scan the subnet. Should get me the IP and machine name

#!bin/bash nokey() { echo "Ключ --all выводит IP-адреса и символьные имена всех узлов в текущей подсети" echo "Ключ --target=XXXX выводит список открытых системных портов TCP" } all() { nbtscan 10.5.115.0/24 } if [ -z "$1" ] then nokey else case "$1" in --all) all ;; --target) #targetfunc ;; esac fi 

Displays this topic enter image description here

1) How can I trim the output so that only the first 2 columns are displayed (grep or sed)? 2) How to make key - target?

  • 1. Better still awk to work with columns. 2. apply something like nmap - Mike
  • one
    use the -e option of the nbtscan program - output "in the format / etc / hosts", i.e., only the name and ip-address. - aleksandr barakin

2 answers 2

Use awk to cut into columns, by type:

 nbtscan 192.168.0.0/24 | awk {'print $1,$2'} 
     #!/usr/bin/env bash nokey() { echo "Ключ --all выводит IP-адреса и символьные имена всех узлов в текущей подсети" echo "Ключ --target=XXXX выводит список открытых системных портов TCP" } all() { local net="$1" nbtscan -k "${net}/24" } target() { local ip="$1" nbtscan"$ip" } main() { if [ "$#" = 0 ]; then nokey else case "$1" in --all) all "$2" ;; --target) target "$2" ;; esac fi } main "$@" # End of script_name 

    I do not understand why so bother with the trabalian task. For myself, I discovered the -oG key in nmap immediately preparing output for mapping (grep, awk)

     ~$ nmap -oG - 172.16.31.76/24 # Nmap 7.40 scan initiated Wed Jul 12 22:25:36 2017 as: nmap -oG - 172.16.31.76/24 Host: 172.16.31.1 () Status: Up Host: 172.16.31.1 () Status: Up Host: 172.16.31.21 () Status: Up Host: 172.16.31.21 () Status: Up Host: 172.16.31.76 () Status: Up Host: 172.16.31.76 () Status: Up Host: 172.16.31.106 () Status: Up Host: 172.16.31.106 () Status: Up # Nmap done at Wed Jul 12 22:25:41 2017 -- 256 IP addresses (4 hosts up) scanned in 4.97 seconds