Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7601335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:08:35+00:00 2026-05-30T23:08:35+00:00

i am trying to write a bash script to determine the ip addresses and

  • 0

i am trying to write a bash script to determine the ip addresses and mac addresses of all hosts available on a network. for some reason, the Pingpacklist file keeps turning up empty. i know that entries in arp aren’t permanent so thought i’d dump the arp after pinging half the network. but it still seems unable to get the arp entries for all addresses. any recommendations?

#! /bin/bash

tcpdump -i eth1 -n icmp >> Pingpacketlist &

count=0
mod=127;
for ip in 172.16.1.{1..254}; do
  let count=count+1;
  let res=$count%$mod;
  ping -c 1 -W 1 $ip > /dev/null 2> /dev/null;
  if [ $? -eq 0 ]; then    # for debugging
    echo "${ip} is up";
  else
    echo "${ip} is down";
  fi 
  if [ $res -eq 0 ]; then
    arp -n -i eth1 >> ARPResults 
  fi
done
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T23:08:37+00:00Added an answer on May 30, 2026 at 11:08 pm

    If you want to record packets with tcpdump, I’d suggest using the -w option (which saves the binary representation of packets to a file), and then parse it afterards. Like this:

    tcpdump -i eth1 -w Pingpacketlist icmp
    

    And then read it back later like this:

    tcpdump -r Pingpacketlist -n
    

    But seriously, if I were trying to accomplish what you’re doing, I would just use nmap. You can use nmap to discover the IP addresses and MAC addresses on your network like this:

    nmap -oX nmap.xml -sP 172.16.1.0/24
    

    You’ll get as output a file (nmap.xml) with contents like this:

    </host>
    <host><status state="up" reason="arp-response"/>
    <address addr="172.16.1.3" addrtype="ipv4"/>
    <address addr="00:1A:70:A9:63:BE" addrtype="mac" vendor="Cisco-Linksys"/>
    <hostnames>
    </hostnames>
    <times srtt="1804" rttvar="5000" to="100000"/>
    </host>
    

    You don’t need to produce XML output if you don’t want it; see Wesley answer for another nmap example.

    If you really want to roll your own, consider looking at the arp table after every successful ping, like this:

    for ip in 192.168.1.{1..254}; do
      ping -c 1 -W 1 $ip > /dev/null 2> /dev/null;
      if [ $? -eq 0 ]; then
        echo "${ip} is up";
        arp -n -i eth0 $ip | grep ether >> ARPResults
      else
        echo "${ip} is down";
      fi
    done
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a bash script that will download all of the youtube
I'm trying to write a simple bash script that accepts all arguments and interprets
I'm trying to write a bash script that would modify all occurrences of a
I'm trying to write a Bash script that uploads a file to a server.
I'm trying to write a bash script that takes a file name, and return
I'm trying to write a simple bash script which should copy all files with
Looking for some help with my bash script. I am trying to write this
I'm trying to write a bash script and I needed to do some floating
I am trying to write a bash script that goes through a file line
I'm trying to write a bash script that will process a list of files

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.