1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

A cool little script

Discussion in 'Linux / Unix Discussion' started by ffreeloader, Oct 26, 2005.

  1. ffreeloader

    ffreeloader Terabyte Poster

    3,661
    106
    167
    The following script is about as basic as they come, but it was a fun little exercise to write. It will take an IP address and a subnet mask and spit out a network address for you. In other words, it will do bitwise anding for you.

    I know it's very simple, but it works and it's fun to accomplish something useful with bash scripting.

    If you have a linux machine you can copy and paste the text into any text editor (gedit, kate, etc...) and then just name the file anything you want as long as it has a .sh extension on it. Then run "chmod u+x whatever_you_named_the_file" from the bash prompt. (If you didn't save the file in your /home directory make sure to include the path to the file in the file name.)To run it just type "./whatever_you_named_the_file." Follow that with a space and then the IP address and subnet mask but instead of using periods in the IP address and subnet mask use spaces.

    Here is the way I enter the command from a bash prompt: ./anding.sh 89 132 97 225 224 224 224 192 This returns the network address for that IP address and subnet mask.

    Here's the script if you're interested.

    Where the smiley shows up in the code is actually a $ and an 8 next to each other. Also, all my formatting is lost when quoting the script, so it doesn't appear here as it is really formatted. I use indentation where appropriate to make the script easier to read.
     
    Certifications: MCSE, MCDBA, CCNA, A+
    WIP: LPIC 1
  2. moominboy

    moominboy Gigabyte Poster

    thanks for all the bash threads freddy, i'm going to be playing around with it in a month or so and i've marked all the ones you've written for reference!


    ta! :tongue
     
    Certifications: ECDL
    WIP: A+

Share This Page

Loading...