Results 1 to 13 of 13

Thread: Create a simple IP Tool Batch File.

  1. #1
    Join Date
    Jan 2009
    Posts
    140

    Create a simple IP Tool Batch File.

    Hey guys!
    I'm new to batch programming. According to my understanding, batch file is logical collection of commands recognised by dos. I am familiar with most of the commands. I want to create a tool which can do three things as follows :

    1 - show ip configurations
    2 - add ip address
    3 - exit

    any idea?

    i don't know how to use loops and jumps.
    can any one guide me??

  2. #2
    Join Date
    Feb 2008
    Posts
    1,852

    Re: Create a simple IP Tool Batch File.

    Code:
    @echo OFF
    :Start
    echo Enter 1 to show TCP/IP Configuration
    echo Enter 2 to add IP ADDRESS
    echo Enter 3 to Exit
    
    ECHO Enter Choice.
    SET /P variable=
    
    IF %variable%==3 exit
    IF %variable%==2 GOTO IPAD
    IF %variable%==1 GOTO IPSH
    
    :IPSH
    ipconfig /all
    GOTO Start
    
    :IPAD
    echo Enter IP address in dotted format [ex: 192.168.10.100] :
    Set /P variable1=
    
    echo Enter subnet mask in dotted format [ex: 255.255.25.0] :
    Set /P variable2=
    
    echo Enter the name of you network connection [ex: Local Area Connection, Lan] :
    Set /P variable3=
    
    netsh interface ip add address %variable3% %variable1% %variable2%
    
    GOTO Start
    Thats the code for the three options you want...!
    Have Fun...!

  3. #3
    Join Date
    Jan 2009
    Posts
    140

    Re: Create a simple IP Tool Batch File.

    Hey Man!
    Thanks a lot i've copied the code in notepad and saved it as ".bat" for batch file...
    I ran it by double clicking on it..! It runs great!
    Thanks man!! I owe this to you...!

  4. #4
    Join Date
    Feb 2008
    Posts
    1,852

    Re: Create a simple IP Tool Batch File.

    Don't Mention it! There's something more for you... I just did some research and added two more features :

    • Add Gateway
    • Add Primary and Secondary DNS


    Heres the complete code :
    Code:
    @echo OFF
    :Start
    echo Enter 1 to show TCP/IP Configuration
    echo Enter 2 to add IP ADDRESS
    echo Enter 3 to add gateway
    echo Enter 4 to add dns
    echo Enter 5 to Exit
    
    ECHO Enter Choice.
    SET /P variable=
    
    IF %variable%==5 exit
    IF %variable%==4 GOTO DNSAD
    IF %variable%==3 GOTO GWAD
    IF %variable%==2 GOTO IPAD
    IF %variable%==1 GOTO IPSH
    
    :IPSH
    ipconfig /all
    GOTO Start
    
    :IPAD
    echo Enter IP address in dotted format [ex: 192.168.10.100] :
    Set /P variable1=
    
    echo Enter subnet mask in dotted format [ex: 255.255.25.0] :
    Set /P variable2=
    
    echo Enter the name of you network connection [ex: Local Area Connection, Lan] :
    Set /P variable3=
    
    netsh interface ip add address %variable3% %variable1% %variable2%
    
    GOTO Start
    
    
    :GWAD
     
    
    echo Enter the name of you network connection [ex: Local Area Connection, Lan] :
    Set /P variable3=
    
    echo Enter gateway in dotted format [ex: 192.168.10.100] :
    Set /P variable4=
    
    netsh interface ip add address "%variable3%" gateway=%variable4% gwmetric=2
    
    
    GOTO Start
    
    :DNSAD
    echo Enter the name of you network connection [ex: Local Area Connection, Lan] :
    Set /P variable3=
    
    echo Enter primary adns ddress in dotted format [ex: 10.168.115.105] :
    Set /P variable5=
    
    echo Enter secondary dns address in dotted format [ex: 10.168.115.105] :
    Set /P variable6=
    
    
    netsh interface ip add dns %varialbe3% %variable5%
    
    netsh interface ip add dns %varialbe3% %variable6% index=2
    
    GOTO Start

  5. #5
    Join Date
    Jan 2009
    Posts
    140

    Re: Create a simple IP Tool Batch File.

    MSpace...
    Your a genius...
    Was just tryin to figure it out the same...
    Thanks again...! So anymore problem i'll PM you instead posting here...!

  6. #6
    Join Date
    Feb 2008
    Posts
    1,852

    Re: Create a simple IP Tool Batch File.

    I suggest whatever problem you have, post it here. Not only you but if someone else has the same problem will be helped...!
    All the best! Try it out... if you discover something... do post...!

  7. #7
    Join Date
    May 2009
    Posts
    2

    question Re: Create a simple IP Tool Batch File.

    hi Mspace,
    new out here..
    saw your replies, seems your are good with batch files , so thought you could help me with this :

    I got two routers and single LAN card. that means 2 gateways and 2 sets of dns.

    I am trying to write a batch file, which on double clicking it, will alternate within the given gateways and dns's.

    Currently i've 2 .bat files - 1.bat and 2.bat. If i want to switch to router 1, i click 1.bat, and if the 2nd router, i double click 2.bat.
    I want to write a batch file which checks what gateway it is in, and switches to other.

    thank you

  8. #8
    Join Date
    Feb 2008
    Posts
    1,852

    Re: Create a simple IP Tool Batch File.

    Hey!
    Try this :
    Code:
    @echo OFF
    :Start
    echo Enter 1 to Switch to 1st DNS and Gateway
    echo Enter 2 to Switch to 2nd DNS and Gateway
    echo Enter 3 to Exit
    
    ECHO Enter Choice.
    SET /P variable=
    
    IF %variable%==3 exit
    IF %variable%==2 GOTO one
    IF %variable%==1 GOTO two
    
    :one
    [here enter path of the 1.bat file without these box bracket]
    
    :two
    [here enter path of the 2.bat file without these box bracket]
    
    :exit
    exit

  9. #9
    Join Date
    May 2009
    Posts
    2

    question Re: Create a simple IP Tool Batch File.

    @myspace: no no.. dude, thats not what i meant.. my requirement is :

    1. I want a single bat file.
    2. when i double click that file, it should switch to other gateway.

    in case you didn't clearly understand, here is the real situation in detail:

    there are 2 routers, r1 and r2.
    so there are 2 gateways , 192.168.1.1 and 192.168.1.2

    when I double click the batch file, it should check which gateway I am currently using, and it should shift to other gateway. Like if the current default gateway is 192.168.1.1, if i double click the .bat file, it should set current gateway as 192.168.1.2.

    I actually created what you suggested by looking at the microsoft kb articles on netsh long ago, but the problem i am facing now is that i dont know how to extract only the gateway from netsh command so that i can use in "if else" check statement in dos commands. FYI, netsh int ip show address "local area connection"
    this statement gets the ip address, subnet mask, gateway, etc from the local area connection adapter. if there is a way to extract the gateway or something like that, we could use the if else construct and do the batch file.

    thank you for your co operation

  10. #10
    Join Date
    Aug 2009
    Posts
    1

    Re: Create a simple IP Tool Batch File.

    shrinath_m2, i had the same problem and used this...

    batch file # 1
    netsh interface ip set address name="Local Area Connection" static 192.168.1.3 255.255.255.0 192.168.1.1 1

    batch file # 2
    netsh interface ip set address name="Local Area Connection" static 192.168.1.3 255.255.255.0 192.168.1.2 1

    batch file # 3
    ipconfig | find "192.168.1.1"
    if not errorlevel 1 goto set2
    call 192.168.1.1.bat
    goto :end
    :set2
    call 192.168.1.2.bat
    :end
    exit

    run batch file #3 and no mather what gateway you're on it will switch to the other one. hope it helps

  11. #11
    Join Date
    Oct 2009
    Posts
    1

    Re: Create a simple IP Tool Batch File.

    I need to create a batch file that whenever a connection is not present on my PC,it will release and renew IP automatic.

    Can anyone help please ?

  12. #12
    Join Date
    Jan 2010
    Posts
    1

    Help Require !!

    Quote Originally Posted by MindSpace View Post
    I suggest whatever problem you have, post it here. Not only you but if someone else has the same problem will be helped...!
    All the best! Try it out... if you discover something... do post...!


    Dear One,

    I want to do two things :-

    1. change only Gateway while using batch file through @echo off
    2. want to add multi IP using batch file


    can you please help me in this regard.

    Shahid Akhtar

  13. #13
    Join Date
    Dec 2011
    Posts
    1

    Re: Create a simple IP Tool Batch File.

    Dear Mind Space
    i think you are genius , i am facing a problem, and i want please help me as soon as you can
    when i want to access some web sites that local ip filter blocks those sites . internet provider proxy has blocked those sites, so i want create a bat file that should bypass the local ip filter and hide my ip address and local internet proxy should not filter my browsing, i mean when connect to the internet my ip address should be from united states of ammerica in spite of united arab emirates
    Asif Raza
    From united arab emirates

Similar Threads

  1. How to make a simple Sorting batch file?
    By nadeth in forum Software Development
    Replies: 3
    Last Post: 18-01-2012, 05:43 AM
  2. How to create a simple logo in Illustrator Tool
    By L 4 Life in forum Windows Software
    Replies: 4
    Last Post: 17-01-2011, 07:31 AM
  3. Replies: 0
    Last Post: 07-03-2009, 01:09 PM
  4. A Simple File and Folder renaming batch code : RenameR
    By Rudra.J in forum Tips & Tweaks
    Replies: 2
    Last Post: 05-03-2009, 02:29 PM
  5. How to create a Batch file
    By Katty in forum Software Development
    Replies: 1
    Last Post: 10-01-2009, 12:56 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,638,559,263.40842 seconds with 16 queries