Help with opening webpage with IP#

Hi,
I would like to open a webpage from an IP# from a file.

Lets say I findout an IP address from using grep
grep John remotecomputers.txt

result: 192.168.2.1

Then after that I would like to increment the IP# to 192.168.2.2 from 192.168.2.1

After that I woud like to launch mozilla or a browser to open up his webpage.

I need help with writing the rest of the script from storing 192.168.2.1 to incremnting it by 1. Then storing it.

Please help, many thanks!

Small script. Don't know if invoking firefox this way will do what you want; play with it if it doesn't.

#!/usr/bin/env ksh

grep John remotecomputers.txt | head - 1 | read junk ip junk   
nxt_ip="${ip%.*}.$(( ${ip##*.} + 1 ))"

firefox "http://$ip"
firefox "http://$nxt_ip"

The "shell magic":

${ip%.*}  # delete the shortest string .* from the contents of the variable as it is expanded
${ip##*.}  # delete the longest string *.  from the contents of the variable as it is expanded
$((  expr ))   # compute the expression in the double parens

The code assumes that the lines in the input file have the IP address as the second token, something like:

John 192.16.18.1  some comments or junk

It will also only use the first line that matches in the input file.

1 Like

I thought thought it would be very simple to a guru.

I just finished my script using the cut and echo command.
It me about 15 line of codes and about 2 hours :slight_smile: