1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Making a script to connect with a specific IP Address

Discussion in 'Tomato Firmware' started by hellspam, Feb 28, 2007.

  1. hellspam

    hellspam LI Guru Member

    Hi, I'm using the tomato firmware, and I'm wondering if I can make a script to tell the router to keep connecting and disconnecting until it has a specific IP. The problem is that a site I use is blocking an IP range of my ISP, but my ISP has two ranges. For example, the site is blocking:
    yyy.yyy.xxx.xxx

    All sites from yyy.yyy.*

    But I can connect to the site using zzz.zzz.xxx.xxx.
    For now, I just redial manually until I get the IP range I want. But I've been wondering if I could make a script that could to that. Anyone know how?
     
  2. Victek

    Victek Network Guru Member

    I'm having similar problem as you described, let's see if some guru can help us. I did some try ... I would like to associate to a SES script button function also (running embeded into the SES button script windows)

    nvram get wan_ipaddr (you get the actual IP)
    if the IP starts with xxx.xxx. ;then
    led amb on
    ifcongif ppp0 down
    ifconfig ppp0 ip-down
    ifconfig ppp0 ip-release
    else
    led white on

    but... I can't transfer these commands to an "intelligent" script..

    Cheers
     
  3. psychowood

    psychowood LI Guru Member

    Just grep the IP, so that if it starts with xxx.xxx you restart the connection:

    =====
    nvram get wan_ipaddr | grep -q ^xxx.xxx

    while [ $? != 0 ] ; do
    led amb on
    ifcongif ppp0 down
    ifconfig ppp0 ip-down
    ifconfig ppp0 ip-release
    nvram get wan_ipaddr | grep -q ^xxx.xxx
    done
    led white on
    =====

    Untested (except for the grep line) but hopefully should work :)
     
  4. Victek

    Victek Network Guru Member

    Hi psychowwod, thanks for your help, some of my commands are wrong and the new one "service wan restart" works awesome. Then the script works in this way:

    =====
    nvram get wan_ipaddr | grep -q ^xxx.xxx
    while [ $? != 0 ] ; do
    led amb on
    service wan restart
    nvram get wan_ipaddr | grep -q ^xxx.xxx
    done
    led white on
    =====
     
  5. psychowood

    psychowood LI Guru Member

    Happy to help :)

    If you want, you could add a sleep (1 sec or 2) in the while loop, just to avoid pulling the CPU on 100% for some time ;)
     
  6. LadFromWales85

    LadFromWales85 Network Guru Member

    psychowood, could you write me a similar script that I could set to run upon establishing a connection, that will check what gateway IP I've been assigned, and will run 'service wan restart' if the gateway IP is not within the several from a single range that I'm hoping to connect with.
    As I do not have a button, I am hoping it'll be possible to do this automatically.

    My isp has 9 LNS servers, split into three BT central pipes. I only want to connect to one central, so connecting to one of 3 gateways would be fine.

    Possible? :D
     
  7. psychowood

    psychowood LI Guru Member

    I'm not sure I understood correctly, my english is lagging, today :biggrin:
    Could you please explain with an example what you need? I don't catch the differences with the script VicTek posted..

    About the button, should not be a problem, you can write (or call) the script in the "WAN Up - Script" section under Administration and it will be run after the router connects for the first time (not too sure about its behaviour, tho).

    [EDIT]Uhm, I think I got it, should have read it twice :). I'll let you know asap.[/EDIT]
     
  8. psychowood

    psychowood LI Guru Member

    Here we go:

    =====
    nvram get wan_gateway | grep -q '^xxx\.xxx\|^yyy\.yyy\|^zzz\.zzz'
    while [ $? != 0 ] ; do
    led amb on
    service wan restart
    sleep 2s
    nvram get wan_gateway | grep -q '^xxx\.xxx\|^yyy\.yyy\|^zzz\.zzz'
    done
    led amb off
    led white on
    =====

    This checks that your gateway either starts with xxx.xxx or yyy.yyy or zzz.zzz . If you have complete IP addresses, just enter them :)
    Note that each '.' should be preceded by '\', so if you want xxx.xxx.xxx.xxx you should write xxx\.xxx\.xxx\.xxx

    As before, led is amber as long as it is trying to get the correct gateway, and goes white when acquired (you can remove the last line if you don't want led white on).

    Put it in Administration -> Scripts -> WAN Up and let me know if it screws up your router ;)
    (Remember to save your tomato configuration BEFORE trying, even if the worst it can do is not upping Wan)
     
  9. LadFromWales85

    LadFromWales85 Network Guru Member

    I have a GSv1.0 so I don't think I have that LED :(

    I'll give your script a go in a second though! :)
     
  10. psychowood

    psychowood LI Guru Member

    Well, I think is a nice bargain losing two leds and a button for double RAM, double Flash size, and SpeedBooster :) anyway, if you want to exchange it with my GL 1.1, just ask :tongue:
     
  11. LadFromWales85

    LadFromWales85 Network Guru Member

    I thought the GSv1.1 had those things...

    I've set the script to turn the DMZ light on instead, and then turn it off when its done. I don't use DMZ, so its ideal :)

    Cheers for your help :D

    EDIT: nm you said you have the GL
     
  12. azeari

    azeari LI Guru Member

    may i ask whats the ^ preceding the ip addresses for? =)
     
  13. psychowood

    psychowood LI Guru Member

    Means "start of line", so that ^xxx.xxx matches xxx.xxx.yyy.yyy but not yyy.xxx.xxx.yyy or yyy.yyy.xxx.xxx :wink:
     
  14. hellspam

    hellspam LI Guru Member

    Just wanted to say thanks for the script!
     
  15. wcwoo

    wcwoo LI Guru Member

    Hi all, I connect to the internet through dynamic ip address provided by the ISP, for example i am getting ip addresses starts with 111.111, 222.222, 333.333, 444.444. I prefer to be connected at the 111.111 ip range. So, can someone enlighten me whether i put in the ip range correctly into the scripts as follows:-

    nvram get wan_ipaddr | grep -q '^222.222/^333.333/^444.444'
    while [ $? != 0 ] ; do
    led amb on
    service wan restart
    nvram get wan_ipaddr | grep -q ^111.111
    done
    led white on
     
  16. wcwoo

    wcwoo LI Guru Member

    Anyone can enlighten me regarding the above matter? (Post #15)
    Thanks in advance!!!!
     

Share This Page