Go Back   WhatIsMyIP.com® Forum > All About Code > Code Requests

Notices

Code Requests People having specific needs to automate their IP retrieval can post their needs here in hopes that a coder can help them out.

Closed Thread
 
Thread Tools Display Modes
Old 11-13-2013, 07:21 AM   #1
JPH
Inactive Member
 
Join Date: Nov 2013
Posts: 1
JPH is on a distinguished road
Default Batch file to display Gateway address

Hi everyone,

I'm a first time poster and I'm really enjoying exploring this site. I was also hoping I would find some assistance from your very knowledgeable community.

I found this post which put me on the right path:

http://forum.whatismyip.com/f52/batc...rnal-ip-t1988/

I was wondering if there was anyway to make the batch file display the current gateway address instead of the IP?

I'm trying to make a few peoples lives easier and it would be nice and simple if I could just tell them to "double click this file and read..."

I addmitantly don't know much about scripting, so thank you in advance for any help you can offer.
JPH is offline  
Old 11-13-2013, 09:29 AM   #2
Shnerdly
• The †erminator
 
Shnerdly's Avatar
 
Join Date: Jun 2010
Location: The frozen tundra of Minnesota
Posts: 1,344
Shnerdly has disabled reputation
Default

Welcome to the forum JPH.

Would the following work?

Code:
@echo off
%windir%\System32\ipconfig.exe /all
pause
It just opens a command prompt and runs ipconfig /all.
__________________


Grammar is important. For instance, commas save lives:

Let's eat grandpa.

OR

Lets eat, grandpa.

Shnerdly is offline  
Old 11-13-2013, 10:27 AM   #3
0siris
Super Moderator
 
0siris's Avatar
 
Join Date: Nov 2009
Location: IL, USA
Posts: 642
0siris will become famous soon enough0siris will become famous soon enough
Send a message via ICQ to 0siris Send a message via AIM to 0siris Send a message via Yahoo to 0siris
Default

Here's a utility that provides a quick display of the computer's routing table. Here's another one.

I can't seem to find a GUI tool that is display only, that explicitly tells you the default gateway. Note that first one requires you to determine which route is the default route. But it doesn't (potentially) allow your users to change things and possibly *really* break stuff.
__________________
Those who expect to reap
the blessings of freedom must,
like men,
undergo the fatigue of supporting it.
-Thomas Paine The Crisis Sep 12, 1777-
0siris is offline  
Old 11-13-2013, 11:22 AM   #4
wimiadmin
Administrator
 
wimiadmin's Avatar
 
Join Date: May 2008
Location: Pigeon Forge, TN
Posts: 1,507
wimiadmin is a splendid one to beholdwimiadmin is a splendid one to beholdwimiadmin is a splendid one to beholdwimiadmin is a splendid one to beholdwimiadmin is a splendid one to beholdwimiadmin is a splendid one to beholdwimiadmin is a splendid one to behold
Default

I don't remember seeing a request like this before so I did some Googling.

I found this http://www.autoitscript.com/forum/to...y-dns-servers/

It would require the autoit software, but nonetheless might work.

I suppose you could write a .bat file that could be stored on a network drive that users have access to. Then as shnerdly suggests, put the ipconfig /all command within that .bat file. The user could execute the .bat and read off the numbers to you.
__________________
Brian
Please Search Before Posting
wimiadmin is offline  
Old 11-13-2013, 09:05 PM   #5
Shnerdly
• The †erminator
 
Shnerdly's Avatar
 
Join Date: Jun 2010
Location: The frozen tundra of Minnesota
Posts: 1,344
Shnerdly has disabled reputation
Default

I tried modifying the original IP bat file and it seems to work for finding the Default Gateway.

Code:
@echo off
IPCONFIG |FIND "Default Gateway" > %temp%\TEMPIP.txt
FOR /F "tokens=2 delims=:" %%a in (%temp%\TEMPIP.txt) do set IP=%%a
del %temp%\TEMPIP.txt
set IP=%IP:~1%
echo %IP% >%temp%\ip.txt
echo Your Gateway IP Address should be "%IP%"
del %temp%\ip.txt
pause
__________________


Grammar is important. For instance, commas save lives:

Let's eat grandpa.

OR

Lets eat, grandpa.

Shnerdly is offline  
Old 11-17-2013, 01:07 AM   #6
MoonPoint
Member
 
Join Date: Nov 2009
Location: U.S.
Posts: 53
MoonPoint is on a distinguished road
Default

If you want to have a file that users double-click on which displays only the default gateway address to a user, you can use a VBScript script. E.g., the following code will provide that information:

strMsg = "Default gateway: "
strComputer = "."

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set IPConfigSet = objWMIService.ExecQuery("Select " _
& "DefaultIPGateway from Win32_NetworkAdapterConfiguration " _
& "WHERE IPEnabled = 'True'")

For Each IPConfig in IPConfigSet
If Not IsNull(IPConfig.DefaultIPGateway) Then
strMsg = strMsg & IPConfig.DefaultIPGateway(i) & vbcrlf
End If
Next

MsgBox strMsg, VBOKOnly, "Default Gateway"


You can use a text editor, such as Notepad, which comes with Microsoft Windows, to create a file containing the code with a .vbs extension (be sure to select "All Files" rather than "Text Documents" in the "Save as type" field if you use Notepad), e.g., defaultgateway.vbs.

If you want more of the information that you might see if you ran "ipconfig /all" at a command prompt, I've created another script ipinfo.vbs. You can retrieve a lot of other information using similar commands, e.g., see Retrieve Client-Side Networking Settings through VBScript for some of the other values you can query. Just remember that you have to treat IP addresses somewhat differently than text information you retrieve or you will get type mismatch errors. E.g, if the "(i)" is omitted after DefaultIPGateway, you would get that error.
MoonPoint is offline  
Old 11-17-2013, 10:24 AM   #7
Shnerdly
• The †erminator
 
Shnerdly's Avatar
 
Join Date: Jun 2010
Location: The frozen tundra of Minnesota
Posts: 1,344
Shnerdly has disabled reputation
Default

@MoonPoint

I have too admit that I am not a coder be any stretch of the imagination but I am able to understand what the commands in a piece of code do once I see them. I tried copying your code into a file and even copied the file from your link but when I run them on my computer, I get the following error:


I tried going to the website you linked to but I get an error there as well:


I am not a big Microsoft fan and have never used Visual Basic. In fact, most of the machines I use are running various flavors of Linux. Is there something I need to add to my computer to run these files? The machine I tried it on is running XP Pro with PaleMoon for a browser. I have also prevented wmiprvse.exe from running on the computer. I mention that because the code calls for the WMI service. Other aspects of the WMI service are available.

Is it likely that the website, activexperts, would require the use of the IE browser??
__________________


Grammar is important. For instance, commas save lives:

Let's eat grandpa.

OR

Lets eat, grandpa.

Shnerdly is offline  
Old 11-17-2013, 10:35 AM   #8
Shnerdly
• The †erminator
 
Shnerdly's Avatar
 
Join Date: Jun 2010
Location: The frozen tundra of Minnesota
Posts: 1,344
Shnerdly has disabled reputation
Default

@MoonPoint

I tried the activexperts website again and it worked. Maybe they were working on the site or something.

I enabled wmiprvse.exe and the scripts still give the same error.
__________________


Grammar is important. For instance, commas save lives:

Let's eat grandpa.

OR

Lets eat, grandpa.

Shnerdly is offline  
Old 11-17-2013, 07:35 PM   #9
MoonPoint
Member
 
Join Date: Nov 2009
Location: U.S.
Posts: 53
MoonPoint is on a distinguished road
Default

Before I posted the scripts, I checked them on a Windows Small Business Server (SBS) 2003 system, XP Professional running as a VM under VMWare on an OS X system, and a Windows 7 Ultimate system. After seeing your message I downloaded them through the links I provided and tried them on two more Windows 7 professional systems, another SBS 2003 server, and a Windows 7 Home Premium system as well as an XP Professional system that wasn't a VM. The scripts executed without any errors on all of them. I've executed them from unprivileged user accounts as well as administrator accouts and on 32-bit and 64-bit versions of Windows; the scripts worked in all cases.

Error: ActiveX component can't create object
Code: 800A01AD

I looked for information on the error above that you reported. At Active Server Pages returns VBScript runtime error '800a01ad', I found the following:

This error is usually generated because dynamic-link libraries (DLLs) on which the COM object depends are one of the following:

•Missing from the system
•Not in the system path
•Not accessible by the system because of security settings


So, perhaps there is some DLL not present or not accessible by the scripts when they are run on your system that is present on all of the other systems, but I don't know which DLL that might be, if that is the cause.
MoonPoint is offline  
Old 11-17-2013, 11:05 PM   #10
Shnerdly
• The †erminator
 
Shnerdly's Avatar
 
Join Date: Jun 2010
Location: The frozen tundra of Minnesota
Posts: 1,344
Shnerdly has disabled reputation
Default

I'll try running them on some other machines and see what happens.

I did expect that you had tested them, I'm just unfamiliar with VB so I don't know what is needed to run the scripts.

I do run my Windows machines very lean. I turn off all programs and protocols that I don't specifically need so I have probably disabled something that the scripts require.
__________________


Grammar is important. For instance, commas save lives:

Let's eat grandpa.

OR

Lets eat, grandpa.

Shnerdly is offline  
Old 11-18-2013, 10:25 AM   #11
0siris
Super Moderator
 
0siris's Avatar
 
Join Date: Nov 2009
Location: IL, USA
Posts: 642
0siris will become famous soon enough0siris will become famous soon enough
Send a message via ICQ to 0siris Send a message via AIM to 0siris Send a message via Yahoo to 0siris
Default

Quote:
Originally Posted by Shnerdly View Post
@MoonPoint

I am not a big Microsoft fan and have never used Visual Basic. In fact, most of the machines I use are running various flavors of Linux. Is there something I need to add to my computer to run these files? The machine I tried it on is running XP Pro with PaleMoon for a browser. I have also prevented wmiprvse.exe from running on the computer. I mention that because the code calls for the WMI service. Other aspects of the WMI service are available.

Is it likely that the website, activexperts, would require the use of the IE browser??
It's not VB or VBScript that's your problem, Schnerdly. If I'm not mistaken, the script Moonpoint showed us is written in PowerShell. that's a new command-line scripting environment starting with Windows... 7? Might have started with Vista.

Powershell uses Windows Management Instrumentation functions to refer to various properties and settings in Windows. Windows XP doesn't have that.

I *think* you can download a version of Powershell for Windows XP. But it's not going to work 100%. XP just doesn't have some of the built-in code that Powershell scripts rely on. I'm not sure if this script is one of those examples.
__________________
Those who expect to reap
the blessings of freedom must,
like men,
undergo the fatigue of supporting it.
-Thomas Paine The Crisis Sep 12, 1777-
0siris is offline  
Old 11-18-2013, 11:34 AM   #12
Shnerdly
• The †erminator
 
Shnerdly's Avatar
 
Join Date: Jun 2010
Location: The frozen tundra of Minnesota
Posts: 1,344
Shnerdly has disabled reputation
Default

Good Morning 0. I got some really wierd results this morning trying these scripts on 6 different computers, all running XP Pro SP3.

3 of them give me the same negative result that I posted earlier. Two of them run both scripts fine and One of them runs the Gateway script but not the ipinfo script.

These are all computers I have setup and configured.

The two that run the scripts are very minimal installations. One is an old PIII that runs a MagicJack phone. The other is a basic install that has DVR software on it for recording my security cameras.

The One that runs the Gateway script but not the other is an older P4 that I use on my work bench for downloading and storing drivers.

The other three are used daily for various things such as XBMC and regular Internet browsing.

I have concluded that it is definitely something I am disabling, either a service or a MS software package. As I said, I run my machines very lean. WinMediaPlayer is physically removed including the support dll's. WMI is partly disabled and many services are turned off such as Shell Hardware Detection, DNS Client, Web Client, Themes and Security Center.

I'll just have to spend some time to see what is causing the problem.
__________________


Grammar is important. For instance, commas save lives:

Let's eat grandpa.

OR

Lets eat, grandpa.

Shnerdly is offline  
Old 11-18-2013, 11:44 AM   #13
wimiadmin
Administrator
 
wimiadmin's Avatar
 
Join Date: May 2008
Location: Pigeon Forge, TN
Posts: 1,507
wimiadmin is a splendid one to beholdwimiadmin is a splendid one to beholdwimiadmin is a splendid one to beholdwimiadmin is a splendid one to beholdwimiadmin is a splendid one to beholdwimiadmin is a splendid one to beholdwimiadmin is a splendid one to behold
Default

Hey Shnerdly, have you tried vmware or virtual PC? This allows an install of a virtual machine on your host. This way if something messes up in the O/S, you can delete the virtual machine without harming the host O/S. Pretty convenient for testing. Once you get a virtual machine setup and configed the way you want, you can copy the files and create many virtual machines from those files quickly. Just a thought.
__________________
Brian
Please Search Before Posting
wimiadmin is offline  
Old 11-18-2013, 11:52 AM   #14
Shnerdly
• The †erminator
 
Shnerdly's Avatar
 
Join Date: Jun 2010
Location: The frozen tundra of Minnesota
Posts: 1,344
Shnerdly has disabled reputation
Default

Good Morning wimiadmin.

I might give that a try. I have never worked with virtual machines. I should probably learn that before I'm too old too.

I do a fair amount of computer recycling so I always have a lot of working unneeded computers around. That's what I usually use for testing things.
__________________


Grammar is important. For instance, commas save lives:

Let's eat grandpa.

OR

Lets eat, grandpa.

Shnerdly is offline  
Old 11-18-2013, 06:48 PM   #15
AboveTheLogic
Super Moderator
 
AboveTheLogic's Avatar
 
Join Date: Jul 2008
Location: Las Vegas
Posts: 727
AboveTheLogic is a glorious beacon of lightAboveTheLogic is a glorious beacon of lightAboveTheLogic is a glorious beacon of lightAboveTheLogic is a glorious beacon of lightAboveTheLogic is a glorious beacon of light
Default

If nothing else, using virtual machines instead of all those old PC's might save you a little bit on your power bill!
AboveTheLogic is offline  
Old 11-18-2013, 09:02 PM   #16
Shnerdly
• The †erminator
 
Shnerdly's Avatar
 
Join Date: Jun 2010
Location: The frozen tundra of Minnesota
Posts: 1,344
Shnerdly has disabled reputation
Default

Quote:
Originally Posted by AboveTheLogic View Post
If nothing else, using virtual machines instead of all those old PC's might save you a little bit on your power bill!
I know your right but the irony is that I will have to setup a new machine to run the virtual machines anyway until get comfortable with it. Then maybe I can consolidate some of my machines.

What VM softwares will run in XP?
__________________


Grammar is important. For instance, commas save lives:

Let's eat grandpa.

OR

Lets eat, grandpa.

Shnerdly is offline  
Old 11-19-2013, 12:47 PM   #17
Shnerdly
• The †erminator
 
Shnerdly's Avatar
 
Join Date: Jun 2010
Location: The frozen tundra of Minnesota
Posts: 1,344
Shnerdly has disabled reputation
Default

I found my problem with the VB scripts. I always disable wmiprvse.exe as a preventative measure on my computers because it is one of the "phone home" components of WMI.

I tried just re-enabling it but that did not do the job. I had to rebuild the repository for WMI after enabling wmiprvse.exe. Then the scripts would run. I guess I'll have to stick to the batch files. I am unwilling to open myself up to unknown outbound activity from my computers.

I looked at the VM softwares that are out there. The free version of VMware seems to be rather complicated, requiring multiple components. I also looked at VirtualBox but had to go all the way back to version 3.1.8 to get a pre-oracle version. I'll probably give VirtualBox a try over the weekend.
__________________


Grammar is important. For instance, commas save lives:

Let's eat grandpa.

OR

Lets eat, grandpa.

Shnerdly is offline  
Old 11-19-2013, 04:39 PM   #18
AboveTheLogic
Super Moderator
 
AboveTheLogic's Avatar
 
Join Date: Jul 2008
Location: Las Vegas
Posts: 727
AboveTheLogic is a glorious beacon of lightAboveTheLogic is a glorious beacon of lightAboveTheLogic is a glorious beacon of lightAboveTheLogic is a glorious beacon of lightAboveTheLogic is a glorious beacon of light
Default

Quote:
Originally Posted by Shnerdly View Post
I know your right but the irony is that I will have to setup a new machine to run the virtual machines anyway until get comfortable with it. Then maybe I can consolidate some of my machines.

What VM softwares will run in XP?
Virtualbox is 100% and runs well. VMWare player is free but is more limited than Virtualbox free.

For home/lab use, Virtualbox is great. For enterprise, though, not so much.

If you want to be brave about it, you can run VMWare ESXi free as a hypervisor and do all your management remotely. It is very cool once you get into it. There is a free variant of Microsoft Hyper-V as well.
AboveTheLogic is offline  
Closed Thread

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 02:02 PM.


What Is My IP

Join WhatIsMyIP.com on Facebook Follow WIMI on Twitter

Need IP address location detection service? Get it from IP2Location.com now.

Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright - WhatIsMyIP.com®