Solved

CAN I DETERMINE NETWORK GATEWAY FROM A DOS COMMAND

Posted on 2010-08-25
9
759 Views
Last Modified: 2012-05-10
I have a need to write a script and need to perform certain actions based on the gateway defined at the client the script is going to run on.

We have several locations and would like to run a script that is relevant to the location they are at and have determine that the network gateway is a good thing to key in on.

Is there way to determine the network gateway from the dos variable or similar.
0
Comment
Question by:yostnet
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +3
9 Comments
 
LVL 24

Accepted Solution

by:
Mike Thomas earned 100 total points
ID: 33520597
"ipconfig" will display that info aswell as the ip and subnet mask if that is any use to you?
0
 

Author Comment

by:yostnet
ID: 33520676
I am aware that I can get the gateway from IPconfig -

But, I need to be able to extract a variable in a batch file without having to parse through a bunch of stuff.
0
 
LVL 42

Assisted Solution

by:sedgwick
sedgwick earned 100 total points
ID: 33520708
you can run the ipconfig and get the result straight into your script which in turn can be processed to get the desired value.please list the requirements from the script and the value you need from ipconfig, and i'll post a script which does that.
0
Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

 
LVL 67

Assisted Solution

by:sirbounty
sirbounty earned 100 total points
ID: 33520762
How about something like this?
@echo off
for /f "delims=: tokens=2" %%a in ('ipconfig^|find "Gateway"') do set gw=%%a
Echo Your gateway address is %gw%

Open in new window

0
 
LVL 43

Assisted Solution

by:Steve Knight
Steve Knight earned 100 total points
ID: 33521169
If you look at my site here there is a script which uses the IP address and splits it up into parts to do similar, perhaops it would help you:

http://scripts.dragon-it.co.uk/links/batch-get-tcpip-subnet?OpenDocument

%subnet% is by default the first three octets of the IP address
%host% is the last octet
%network% is the third octet

e.g.

192.168.1.45
subnet=192.168.1
network=1
host=45



@echo off
for /f "tokens=2 delims=:" %%a in ('ipconfig ^|find "IP Address"') do call :process %%a & goto :next
:next
echo Subnet is %subnet% and host is %host%
set site=Unknown
if %network%==10 set site=SiteA
if %network%==20 set site=SiteB
if %network%==30 set site=SiteC
if %network%==40 set site=SiteD
if %subnet%==192.168.1 set site=SiteE
if %subnet%==128.127.1 set site=Dragon-IT

echo site is %site%

goto :Eof

:process
echo Found %1
for /f "tokens=1-4 delims=." %%a in ("%1") do (set subnet=%%a.%%b.%%c)&(set host=%%d)&(set network=%%c)
0
 
LVL 26

Assisted Solution

by:pony10us
pony10us earned 100 total points
ID: 33523103
Here is some code to find the default gateway another way as taken from the discussion here:

http://www.petri.co.il/forums/showthread.php?t=47121

@For /f "tokens=3" %%* in (
'route.exe print ^|findstr "\<0.0.0.0\>"'
) Do @Set "DefaultGateway=%%*"

Open in new window

0
 

Author Comment

by:yostnet
ID: 33561411
thanks - will review |
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 33571134
Little miffed that the "accepted answer" and points went to the suggestion of "look at ipconfig" rather than one of the scripts that gave you what you wanted in different ways...
0
 
LVL 26

Expert Comment

by:pony10us
ID: 33571156
Thank you for the points. I hope you received enough options.  :)
0

Featured Post

Business Impact of IT Communications

What are the business impacts of how well businesses communicate during an IT incident? Targeting, speed, and transparency all matter. Find out more in this infographic.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Autorun Remote Desktop - USB Stick 6 86
Batch rename files sequentially and move 7 51
Hta File displays dynamic File names 4 65
Add Log to powershell Script 14 29
AutoHotkey is an excellent, free, open source programming/scripting language for Windows. It started out as a keyboard/mouse macros product, but has expanded into a robust language. This article provides an introduction to it, with links to addition…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question