SitePoint Sponsor

User Tag List

Results 1 to 17 of 17

Hybrid View

  1. #1
    SitePoint Evangelist
    Join Date
    Apr 2005
    Posts
    485
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Howto Go About Possible Ruby Application

    hi all,

    i'm delving into RoR a bit. i'm learning, but still have a ways to go.

    anyway, my friend approached me about coding an app with the following criteria:

    1. check modem's external ip at regular intervals
    2. send email with new ip address when it changes.

    i suppose this could be done via RoR and using ajax to check this info on a wbe page, but i think we can agree that's hackish.

    can i program something like this as a standalone ruby app and make it cross platform.

    it seems like a cool project b/c, in theory, it is trivial and i'd get to learn how to work with ruby on a standalone app.

    if this is possible, can anyone lead me to some resources explaining how to get it done?

    tia...

  2. #2
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    Oklahoma
    Posts
    119
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by skeeterbug
    hi all,

    i'm delving into RoR a bit. i'm learning, but still have a ways to go.

    anyway, my friend approached me about coding an app with the following criteria:

    1. check modem's external ip at regular intervals
    2. send email with new ip address when it changes.

    i suppose this could be done via RoR and using ajax to check this info on a wbe page, but i think we can agree that's hackish.

    can i program something like this as a standalone ruby app and make it cross platform.

    it seems like a cool project b/c, in theory, it is trivial and i'd get to learn how to work with ruby on a standalone app.

    if this is possible, can anyone lead me to some resources explaining how to get it done?

    tia...
    I've written almost an identical app to keep my server synced with a dynamic DNS service. I did most of the work using the standard library's HTTP classes. I made an HTTP connection outbound to a site that returned my external IP (this was important because thanks to NAT my machines IP is not truly external). I then took that result, parsed it into an IP address, and then submitted another request to the dyndns service telling it to update my record.

    The entire script, including comments, command line help, and whitespace is 60 lines. I'm sure with what i've learned since I wrote it I could cut that way down, but regardless its a pretty simple, but good learning project.

    [edit]I spent the last 5 minutes making some minor style tweaks, and a little general cleaning. I dropped a good 5 or 6 lines without hurting readability. In fact I improved the performance a bit

  3. #3
    SitePoint Evangelist
    Join Date
    Apr 2005
    Posts
    485
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Sgarissta
    I've written almost an identical app to keep my server synced with a dynamic DNS service. I did most of the work using the standard library's HTTP classes. I made an HTTP connection outbound to a site that returned my external IP (this was important because thanks to NAT my machines IP is not truly external). I then took that result, parsed it into an IP address, and then submitted another request to the dyndns service telling it to update my record.

    The entire script, including comments, command line help, and whitespace is 60 lines. I'm sure with what i've learned since I wrote it I could cut that way down, but regardless its a pretty simple, but good learning project.
    Sqarissta, is there a way to create a self contained ruby executable or does ruby need to be installed on the system? i'll have to look through the http classes to see what they allow me to do.

    i'll try and script it on my home linux box. i suppose i could cron the file, which is something i need to learn, too. when i get it running, i'll have to learn how to schedule a task on windows.

    i guess it is time to learn even more stuff.

  4. #4
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    Oklahoma
    Posts
    119
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by skeeterbug
    Sqarissta, is there a way to create a self contained ruby executable or does ruby need to be installed on the system? i'll have to look through the http classes to see what they allow me to do.
    You can look into RubyScript2Exe, it creates an executable containing your script, its dependant libraries, and the ruby executable itself. When you run it it unpacks this behind the scenes, and executes it. The end result is that you have a single exe that allows you to distribute and run a ruby script.
    i'll try and script it on my home linux box. i suppose i could cron the file, which is something i need to learn, too. when i get it running, i'll have to learn how to schedule a task on windows.

    i guess it is time to learn even more stuff.
    The scriptable equivilent of cron on windows is the 'at' command.

  5. #5
    SitePoint Evangelist
    Join Date
    Apr 2005
    Posts
    485
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Sgarissta
    You can look into RubyScript2Exe, it creates an executable containing your script, its dependant libraries, and the ruby executable itself. When you run it it unpacks this behind the scenes, and executes it. The end result is that you have a single exe that allows you to distribute and run a ruby script.

    The scriptable equivilent of cron on windows is the 'at' command.
    Sgarissta, thanks for the information. RubyScript2Exe sounds cool.

    i don't think i need to worry about a NAT. i found the following ruby script that is alledged to work:

    Code:
    ruby -ropen-uri -e "URI.parse('http://www.whatismyip.com').read =~ /((\d+\.?){4})/; puts $&"
    if this works (i can't test until later), then all i need to do is assign the ip to a variable, check against the prior ip and then email it off if they aren't the same...

  6. #6
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    Oklahoma
    Posts
    119
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by skeeterbug
    Sgarissta, thanks for the information. RubyScript2Exe sounds cool.

    i don't think i need to worry about a NAT. i found the following ruby script that is alledged to work:

    Code:
    ruby -ropen-uri -e "URI.parse('http://www.whatismyip.com').read =~ /((\d+\.?){4})/; puts $&"
    if this works (i can't test until later), then all i need to do is assign the ip to a variable, check against the prior ip and then email it off if they aren't the same...
    That code goes around the NAT by doing what my script does, which is go out to a public website that displays your IP address.

  7. #7
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    268
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if I recall correctly (which is a gamble) $& is a variable that will be holding the results of the regex expression.
    the " closes the " started in "URI.parse....

    the regex says you will have 4 groups of the following: 1 or more digits followed by 0 or 1 periods

    It would be better if it specified a range of digits, rather than accepting an IP like 29292.29239213.123993.1 but I might have read it wrong..

    edit:
    I was right.
    $& holds the String of the last Match whenever you use regex


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
  •