Find the answer to your Linux question:
Results 1 to 5 of 5

Thread: Simple Script

Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Simple Script

    I'm trying to get a simple script to try pinging all possible computers on a subnet (say 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
    Stockholm, Sweden

    This should give you a good start.

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


    here's a start
    for &#40;&#40;a=1; a <= $txt ; a++&#41;&#41; 
    ping -c 1 192.168.20.$a
    save this as a file e.g. script and make it executable
    then run something like this ./script 4 it will ping 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. $spacer_open
  5. #4
    Just Joined!
    Join Date
    Mar 2004
    Wrexham UK
    if you have nmap installed.....
    nmap -sP
    will give you a list of all the IPs that are active on a subnet then
    nmap -sL
    will give a list of all possible IPs on a subnet

  6. #5
    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?

    while &#91; $COUNTER -lt 15 &#93;; do
    	ping $1.$COUNTER -c 1 -i 100
    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