Check, obtain IP and open internet explorer by batch file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
LFC
Posts: 5
Joined: 06 Jan 2010 11:48

Check, obtain IP and open internet explorer by batch file

#1 Post by LFC » 07 Jan 2010 12:39

Hi,

I wanted to know if you can check and get the ip of a site, for example dostips.com,
To this end I am using: nslookup dostips.com 8.8.8.8
and the result is:

-----------------------------------------------
Server: google-public-dns-a.google.com
Address: 8.8.8.8

Non-authoritative answer:
Name: dostips.com
Address: 66.96.133.6
-----------------------------------------------

Then I want to save the ip found previously (in this example would be the ip 66.96.133.6) in a variable (eg called TargetIP)

Finally open the internet explorer as follows: http://TargetIP/forum
(Possibly through: start http://TargetIP/forum)

Someone can help me to create the code in a batch file?

Thank you in advance, any help is welcome.

Best regards

sweener
Posts: 18
Joined: 06 Jan 2010 13:00
Location: Indianapolis, IN

#2 Post by sweener » 07 Jan 2010 13:16

Try something like this:

Code: Select all

ping dostips.com -n 1 |FINDSTR "Reply" > tmp.txt
FOR /F "tokens=3 delims=: " %%a in (tmp.txt) do set targetIP=%%a

"C:\Program Files\Internet Explorer\IEXPLORE.EXE" %targetIP%

Of course, you can add the path that your internet explorer resides in into your $PATH variable so you would just use > IEXPLORE %targetIP%

Note: In the FOR statement, there is a space after the semi colon which maintains the space as a delimiter.

I don't know if this is what you are looking for but I hope it's a step in the right direction.

LFC
Posts: 5
Joined: 06 Jan 2010 11:48

#3 Post by LFC » 09 Jan 2010 07:34

Hi,

Excellent sweener the code works perfectly with the command ping but my goal would be to use the command nslookup.
The problem is that when I do:

----------------------------------------------------------------------
nslookup dostips.com 8.8.8.8 |FINDSTR "Address:" > tmp.txt
----------------------------------------------------------------------

The file tmp.txt is written:

Address: 8.8.8.8
Address: 66.96.133.6


Therefore, the next step would be to write to the variable TargetIP the address (66.96.133.6) is located on the second line of the file tmp.txt.

After the second difficulty arises when it is necessary to add the following set of characters /forum to address (66.96.133.6) in the address bar of internet explorer, ie, open directly in Internet Explorer's page dostips.com Forum:

http://66.96.133.6/forum is the same as: http://TargetIP/forum

So when you run the code, the Internet Explorer automatically opens the Forum page.
This would be the main objective.

You have any idea how to solve this problem?
Once again thanks your invaluable help and speed of response.

sweener
Posts: 18
Joined: 06 Jan 2010 13:00
Location: Indianapolis, IN

#4 Post by sweener » 09 Jan 2010 10:28

You could do something like this but there are several approaches:

Code: Select all

@ECHO OFF
nslookup dostips.com 8.8.8.8|findstr "Address:" > tmp.txt
FOR /F "tokens=2 skip=1 delims=: " %%d in (tmp.txt) do SET targetip=%%d ::NOTE the <SPACE> in the delims part
"%IEXPLORERPATH%\IEXPLORE.EXE" %targetip%/%~1


%~1 is the argument supplied to the script so if you wanted to add /forum, you'd type >scriptname forum

Even though you'll still get two IPs in temp.txt, the skip=1 skips the first one. It can be coded so you get 'Address:IP' after the STDERR output of 'Non-authoritative answer:' but IF this simple fix works, great ELSE I'll code my other idea for you.

Let me know if this works...

LFC
Posts: 5
Joined: 06 Jan 2010 11:48

#5 Post by LFC » 11 Jan 2010 12:41

Excuse me my insistence but I still can not add /forum to the address (66.96.133.6) in the address bar of Internet Explorer, ie,
In Internet Explorer I can not open: http://66.96.133.6/forum

There is a detail as I'm not understand.
You can do it help how to solve this problem please?

sweener
Posts: 18
Joined: 06 Jan 2010 13:00
Location: Indianapolis, IN

#6 Post by sweener » 11 Jan 2010 13:05

Hmmm, do you get a blank page when you try it without 'forum' as an argument to the batch? And when you do it with 'forum' does it say "Page Not Found" followed by some other info?

It works for other websites... Replace Dostips.com in your script with another known URL... I dunno if it is something the admin folks for this site have set up or not...

When you try my initial 'ping' method, the Dostips website is not popping up like before. Maybe they don't want us doing that??

LFC
Posts: 5
Joined: 06 Jan 2010 11:48

#7 Post by LFC » 13 Jan 2010 04:22

Hi sweener, your help was essential for the majority resolution of the problem so I can only express my greatest gratitude for your help and your constant availability. Cheers.

LFC
Posts: 5
Joined: 06 Jan 2010 11:48

Re: Check, obtain IP and open internet explorer by batch file

#8 Post by LFC » 22 Jan 2010 06:21

Hi swenner,
Do you can help me please the following problem:
Since it was able to obtain the address using the method discussed above, the next step would be able to write a text file (IPlist.txt) the IP address before the address name.
Given that the contents of the file IPlist.txt is:
___________________________________________________
# List of IP addresses stored in the text file:
207.68.172.246 msn.com
209.85.229.147 google.com
66.96.133.6 dostips.com
209.251.180.18 usa.gov
___________________________________________________

and is saved in: "C:\Users\TOSHIBA\IPlist.txt"

The main objective will be to get the IP address of dostips.com (for example) through:
------------------------------------------------------------------------
@ECHO OFF
nslookup dostips.com 8.8.8.8|findstr "Address:" > tmp.txt
FOR /F "tokens=2 skip=1 delims=: " %%d in (tmp.txt) do SET targetip=%%d
------------------------------------------------------------------------

and then replace the old IP address (66.96.133.6) that is in the text file (IPlist.txt) for the new IP address found by nslookup (for example let's assume that nslookup gave the new IP address 198.199.200.201).
So when you run the script, the text file (IPlist.txt) would be with the following contents:
___________________________________________________
# List of IP addresses stored in the text file:
207.68.172.246 msn.com
209.85.229.147 google.com
198.199.200.201 dostips.com
209.251.180.18 usa.gov
___________________________________________________

In summary, the main objective is to update the IP addresses in a text file ("C:\Users\TOSHIBA\IPlist.txt") stored on my computer's hard drive every time I run nslookup.
Best Regards

Post Reply