Announcement

Collapse
No announcement yet.

Batch File to Change Gateway only

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Batch File to Change Gateway only

    Hi there, i have a network with 40 pc and two gateways what i need is a bat file to redirect torrent traffic to one specific gateway the problem is that each pc has a static ip and i don't want to modify any setting except gateway so what i have done till now is this :
    Code:
    @echo off
    taskkill /F /IM utorrent.exe
    netsh interface ip set address name="Local Area Connection" source=dhcp gateway=192.168.1.130 gwmetric=1
    start /wait C:\Progra~2\uTorrent\utorrent.exe
    netsh interface ip set address name="Local Area Connection" source=dhcp gateway=192.168.1.1 gwmetric=1
    exit
    but his doesnt work cause it changes ip and net mask to dhcp instead of just changing gateway

    So what i have in mind is to use command ipconfig > C:\ip.txt then use a findstr 0.0.0.0 to find the static values for ip, subnetmask and then paste each value like netsh interface ip set address name="Local Area Connection" source=static addr=% mask=% gateway=192.168.1. gwmetric=1
    i have the general concept just cant do it
    I appreciate any help
    Last edited by Broderic; 17th July 2013, 09:47.

  • #2
    Re: Batch File to Change Gateway only

    I really shouldn't respond since you mentioned the "T" word, which normally involves inappropriate/illegal files, but a quick question to my friend gives one or two responses -- see the second link here:
    https://www.google.co.uk/search?q=ne...Bqi70QXZi4GIAw
    Tom Jones
    MCT, MCSE (2000:Security & 2003), MCSA:Security & Messaging, MCDBA, MCDST, MCITP(EA, EMA, SA, EDA, ES, CS), MCTS, MCP, Sec+
    PhD, MSc, FIAP, MIITT
    IT Trainer / Consultant
    Ossian Ltd
    Scotland

    ** Remember to give credit where credit is due and leave reputation points where appropriate **

    Comment


    • #3
      Re: Batch File to Change Gateway only

      Originally posted by Ossian View Post
      I really shouldn't respond since you mentioned the "T" word, which normally involves inappropriate/illegal files, but a quick question to my friend gives one or two responses -- see the second link here:
      Trust me there is nothing illegal with T command since it would be a bug in case the client had already opened utorrent.... google wasnt that help full :S

      Comment


      • #4
        Re: Batch File to Change Gateway only

        In your first post you specifically say "redirect torrent traffic to one specific gateway while utorrent is running" but we will leave that aside for now.

        Did you actually read the second link on the search I posted?
        http://www.autoitscript.com/forum/to...nly-by-script/
        It appears to deal with exactly the situation you have
        Tom Jones
        MCT, MCSE (2000:Security & 2003), MCSA:Security & Messaging, MCDBA, MCDST, MCITP(EA, EMA, SA, EDA, ES, CS), MCTS, MCP, Sec+
        PhD, MSc, FIAP, MIITT
        IT Trainer / Consultant
        Ossian Ltd
        Scotland

        ** Remember to give credit where credit is due and leave reputation points where appropriate **

        Comment


        • #5
          Re: Batch File to Change Gateway only

          Maybe you can use a route.exe command to change the current default gateway IPv4 address,
          Code:
          Route.exe CHANGE 0.0.0.0 MASK 0.0.0.0 <ip4address>
          The sample below works on Windows Vista and later* (64 bit and 32 bit). The batch should run elevated.
          (*The timeout command does not work on Windows XP and earlier)

          Code:
          @echo off
          
          Set "DefGW2=192.168.1.1" (temp default gateway)
          
          IF NOT DEFINED ProgramFiles(x86) CALL SET "ProgramFiles(x86)=%ProgramFiles%"
          
          If not exist "c:\backup_NIC_config\nic.cfg" (
            MKDIR      "c:\backup_NIC_config"
            Netsh.exe -c Interface DUMP >"c:\backup_NIC_config\nic.cfg")
          
          call Set "DefGW2=0.0.0.0 MASK 0.0.0.0 %DefGW2% -P METRIC 2"
          
          Route.exe ADD %DefGW2%
          
          taskkill /im "uTorrent.exe" /f
          
          :whilestopping
          timeout /t 3 /NoBreak
          tasklist.exe | find /i "uTorrent.exe" && goto:whilestopping
          
          start ""/wait "%ProgramFiles(x86)%\uTorrent\uTorrent.exe"
          timeout /t 3
          
          Route.exe DELETE %DefGW2%
          What is the OS of the computer(s)? I assume they are not virtual machines?

          /Rems
          Last edited by Rems; 8th July 2013, 22:55.

          This posting is provided "AS IS" with no warranties, and confers no rights.

          __________________

          ** Remember to give credit where credit's due **
          and leave Reputation Points for meaningful posts

          Comment


          • #6
            Re: Batch File to Change Gateway only

            Originally posted by Ossian View Post
            In your first post you specifically say "redirect torrent traffic to one specific gateway while utorrent is running" but we will leave that aside for now.

            Did you actually read the second link on the search I posted?

            It appears to deal with exactly the situation you have
            yeah i need to edit the post and delete the "while utorrent is running" done
            the second post from google adds the ip but does not sets so it is not what i need
            Last edited by Broderic; 17th July 2013, 10:48.

            Comment


            • #7
              Re: Batch File to Change Gateway only

              Originally posted by Rems View Post
              What is the OS of the computer(s)? I assume they are not virtual machines?
              /Rems
              they are all running windows 7 EN home premium x64 , i am going to have to give ago for your script at work environment as it has commands and conditions i am not familiar with and i cant follow your code, will get back to you, in the meantime i was putting together something of my own

              Code:
               @echo off
              taskkill /F /IM utorrent.exe
              setlocal
              FOR /F "tokens=*" %%i in ('ipconfig ^| find "IPv4"') do SET result=%%i
              echo %result:IPv4 Address. . . . . . . . . . . : =% | clip
              netsh interface ip set address "Local Area Connection" static %result% 255.255.255.0 192.168.1.130
              start /wait C:\Progra~2\uTorrent\utorrent.exe
              netsh interface ip set address name="Local Area Connection" source=static %result% mask=255.255.255.0 gateway=192.168.1.131
              endlocal
              exit
              though something is wrong with it and i am too lazy atm to find out what it is oh plus another thing that is wrong with my code is that in case utorrent is not running it prompts for user action so i guess i would need a condition to skip that part ?
              Last edited by Broderic; 17th July 2013, 10:50.

              Comment

              Working...
              X