Find the answer to your Linux question:
Results 1 to 5 of 5
I'm trying to get a simple script to try pinging all possible computers on a subnet (say 192.168.0.0) Not i know u can use a for loop, but i not ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux Guru sdousley's Avatar
    Join Date
    Feb 2004
    Posts
    1,790

    Simple Script


    I'm trying to get a simple script to try pinging all possible computers on a subnet (say 192.168.0.0) Not i know u can use a for loop, but i not had experience in scripting of this type, and don't know where to start! It has to be in a batch file, and output the arp cache to a file so i can c the ip address/mac address of all computers on the network.
    Now i know u could use SNMP, but this is for uni, and the lecturer wants us to do it this way to c how it's done.

    Basically need a script to ping 192.168.0.x where x ranges from 1 to 254. then output the arp cache to a file arp.txt.
    "I am not an alcoholic, alcoholics go to meetings"
    Registered Linux user = #372327

  2. #2
    Linux Engineer
    Join Date
    Jul 2003
    Location
    Stockholm, Sweden
    Posts
    1,296
    http://www.fokus.gmd.de/linux/HOWTO/...og-Intro-HOWTO

    This should give you a good start.

  3. #3
    Linux User
    Join Date
    Jan 2003
    Location
    Cardiff, Wales
    Posts
    478

    start

    here's a start
    Code:
    txt=$* 
    
    for &#40;&#40;a=1; a <= $txt ; a++&#41;&#41; 
    do
    ping -c 1 192.168.20.$a
    done
    save this as a file e.g. script and make it executable
    then run something like this ./script 4 it will ping 192.168.20.1 etc up to 4 displaying results on the screen.

    now at the command line work out how to redirect the output into a file or maybe into something like grep to extract the results you need. or just dump the arp cache to a file using a redirector dostuff > test.txt

    that should start you off. I don't know much about this so I've spent a while searching for you. let me know what you come up with at the end.
    No trees were harmed during the creation of this message. Its made from a blend of elephant tusk and dolphin meat.

  4. #4
    Just Joined!
    Join Date
    Mar 2004
    Location
    Wrexham UK
    Posts
    14
    if you have nmap installed.....
    nmap -sP 192.168.0.0/24
    will give you a list of all the IPs that are active on a subnet then
    nmap -sL 192.168.1.0/24
    will give a list of all possible IPs on a subnet

  5. #5
    Linux Guru sdousley's Avatar
    Join Date
    Feb 2004
    Posts
    1,790
    Cool! I have actually got a simple script from the guide Variant posted, but now because uni only uses windows! I have to change it to windows command prompt so i can show the lecturer! Any one know how this code would look in a windows batch file?

    Code:
    #!/bin/bash
    COUNTER=1
    while &#91; $COUNTER -lt 15 &#93;; do
    	ping $1.$COUNTER -c 1 -i 100
    	let COUNTER=COUNTER+1
    done
    arp -a > arp.txt
    "I am not an alcoholic, alcoholics go to meetings"
    Registered Linux user = #372327

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •