Mr_Chmod
Mr_Chmod

Reputation: 1

I want to add another IP address octet (255.255.x.y,) in a Bashscript code

I want to add another octet (192.168.x.i) to the following script:

IPPFX=$1
for i in `seq 1 255` ; do LIST="$LIST ${IPPFX}.$i" ; done
for i in $LIST ; do
    ENTRY="`host $i`"
    [ $? -ne 0 ] && continue
    ENTRY=`echo "$ENTRY" l sed -e 's/.* //' -e 's/\.$//'`
    echo -e "$i\t$ENTRY"
done

I tried adding

IPPFX=$1
for i in `seq 1 255` ;
for j in `seq 1 255` do LIST="$LIST
${IPPFX}.$j.$i" ; done 
for i in $LIST ;
for j in $LIST ; do
    ENTRY="`host $j.$i`"
    [ $? -ne 0 ] && continue
    ENTRY=`echo "$ENTRY" l sed -e 's/.* //' -e 's/\.$//'`
    echo -e "$j$i\t$ENTRY"
done

Upvotes: 0

Views: 41

Answers (1)

M. Nejat Aydin
M. Nejat Aydin

Reputation: 10133

Probably you want for something like this:

#!/bin/bash

ippfx=$1
for ip in "$ippfx".{0..255}.{0..255}; do
    entry=$(host "$ip" | sed 's/.* //; s/\.$//') || continue
    printf '%s\t%s\n' "$ip" "${entry//$'\n'/ }"
done

Call the script like

./tst 216.58

with two octets.

Upvotes: 1

Related Questions