Help me with the syntax of this bat file that changes my ip address

Page 1 of 2 12 LastLast

  1. Posts : 10
    Windows 7
       #1

    Help me with the syntax of this bat file that changes my ip address


    netsh interface ip set address name="Wireless
    Network Connection" static 192.168.1.64
    255.255.255.0
    192.168.1.%RANDOM% * (%300% - %1% + 1);

    #//192.168.1.254
    #//%RANDOM% * (%888% - %01% + 1)
    #//%RANDOM% * (%maxval% - %minval% + 1) / 32768 + %minval%;

    Wont work, and in shell scripting what makes the line dormant? the # or // ?
      My Computer


  2. Posts : 5,656
    Windows 7 Ultimate x64 SP1
       #2

    I will ask one of our programming experts, he may not be checking this section of the forums.
      My Computer


  3. Posts : 10
    Windows 7
    Thread Starter
       #3

    GokAy said:
    I will ask one of our programming experts, he may not be checking this section of the forums.
    Let me know what he says
      My Computer


  4. Posts : 721
    Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
       #4

    Hi Delta,

    I'm finding it difficult to help you as you haven't yet explained what your batch file is to do, or the problem/s you are having with your current script (there are quite a few). And the batch file you've posted makes it none the clearer to me of your intent: # and // at the beginning of a command line is nothing more than a syntax error to me.

    Meanwhile, this may help -- here is a small example of a batch file that changes one's IP address to 192.168.1.x, where x is any integer between 10 and 255 (inclusive).
    Code:
    @echo off
    
    set interface_name="Wireless Network Connection"
    set ipaddr_front=192.168.1
    set /a ipaddr_end=(255 * %RANDOM%)/32768+10
    set subnet_mask=255.255.255.0
    
    netsh interface ip set address %INTERFACE_NAME% static %IPADDR_FRONT%.%IPADDR_END% %SUBNET_MASK%
      My Computer


  5. Posts : 5,656
    Windows 7 Ultimate x64 SP1
       #5

    Thanks for your input Pyprohly.

    255 should not be included (for this case), it is the broadcast address for the network for this subnet mask (255.255.255.0). (the last IP in the subnet is broadcast, so may be different for classless networks). Say, for example, for 255.255.0.0 subnet you can have an IP ending as 0.255 or 1.255 etc but not 255.255
      My Computer


  6. Posts : 10,485
    W7 Pro SP1 64bit
       #6

    Some network devices will not accept traffic from IP addresses that are outside or the DHCP range.

    e.g. if the DHCP range is 192.168.1.100 to 192.168.1.150 and the batch file assigns the computer 192.168.1.15, then no traffic will flow to that computer. The vendor claimed this is a security feature. I called it an annoyance.
    Last edited by UsernameIssues; 11 Sep 2015 at 12:29.
      My Computer


  7. Posts : 721
    Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
       #7

    @GokAy Have I made an obvious mistake somewhere? Please elaborate if so.
      My Computer


  8. Posts : 5,656
    Windows 7 Ultimate x64 SP1
       #8

    Sorry for not being clear about it.

    where x is any integer between 10 and 255 (inclusive).
    It should be 254 max in this case. So,
    Code:
    set /a ipaddr_end=(255 * %RANDOM%)/32768+10
    should be
    Code:
    set /a ipaddr_end=(254 * %RANDOM%)/32768+10
    right?
      My Computer


  9. Posts : 5,656
    Windows 7 Ultimate x64 SP1
       #9

    And something I noticed right now, if you are adding 10 by default, it should be 244 instead?

    I get %RANDOM% returns an integer between 0 (or 1?) and 32768?

    Ok, did some searching and it is 0-32768.

    Also found this,

    what do you think about?
    Code:
    set /a ipaddr_end=%RANDOM% %%244 +10
    I tested in cmd, there %RANDOM% % 244+10 seem to work (single % before 244 instead of %% in script)
      My Computer


  10. Posts : 10
    Windows 7
    Thread Starter
       #10

    Pyprohly said:
    Hi Delta,

    I'm finding it difficult to help you as you haven't yet explained what your batch file is to do, or the problem/s you are having with your current script (there are quite a few). And the batch file you've posted makes it none the clearer to me of your intent: # and // at the beginning of a command line is nothing more than a syntax error to me.

    Meanwhile, this may help -- here is a small example of a batch file that changes one's IP address to 192.168.1.x, where x is any integer between 10 and 255 (inclusive).
    Code:
    @echo off
    
    set interface_name="Wireless Network Connection"
    set ipaddr_front=192.168.1
    set /a ipaddr_end=(255 * %RANDOM%)/32768+10
    set subnet_mask=255.255.255.0
    
    netsh interface ip set address %INTERFACE_NAME% static %IPADDR_FRONT%.%IPADDR_END% %SUBNET_MASK%

    This is the original script

    netsh interface ip set address name="Wireless Network Connection" static 192.168.1.64 255.255.255.0 192.168.1.254;

    its supposed to change any variable inbetween each dot within each address
      My Computer


 
Page 1 of 2 12 LastLast

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 07:48.
Find Us