Announcement

Collapse
No announcement yet.

help with IP script

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

    help with IP script

    I have a very basic script that I use to go out to checkip.dyndns.org to get my current IP address. It is working very well except I use a character option to strip out the ip address from the url page. This is normally ok but every once in a while my IP address is one character shorter or longer.

    I wanted to know if some one has a better way to strip out the numbers of the IP address that gets returned from the geturl command and save them to a device?

    attached is the script I have now.

    *'``'*:-.,_,.-:*'``'*:-Fit4Life-:*'``'*:-.,_,.-:*'``'*
    Attached Files

    #2
    <pre class="ip-ubbcode-code-pre">
    pos=Instr(page,"Current IP Address:") + 20
    len=Instr(pos+1,page,chr(13)) - pos + 1
    ip=Mid(page, pos, len)
    </pre>

    Haven't tested this. If it doesn't work, try changing chr(13) to chr(10) and it'll probably work then.

    Nucleus Home Automation | System Specs
    News, support, and updates for Rover, Network Monitor, TimeIcons, and more

    Comment


      #3
      Hunter,

      I changed what I had and now I get an error:


      4/5/2003 10:05:37 PM~!~Error~!~Script error in file: myip.txt: 501:Illegal assignment: 'len' in line 22

      Any ideas?

      *'``'*:-.,_,.-:*'``'*:-Fit4Life-:*'``'*:-.,_,.-:*'``'*

      Comment


        #4
        LEN is a reserved keyword in VBS. Change it to something else, like:

        pos=Instr(page,"Current IP Address:") + 20
        string_len=Instr(pos+1,page,chr(13)) - pos + 1
        ip=Mid(page, pos, string_len)


        Mitch

        http://www.midondesign.com
        http://www.midondesign.com

        Comment


          #5
          Boy, is my face red.

          (What can I say... I've been doing C for a while and haven't dipped my finger in VBScript in months.)

          Nucleus Home Automation | System Specs
          News, support, and updates for Rover, Network Monitor, TimeIcons, and more

          Comment


            #6
            Still NG. This is the error I get now:

            4/6/2003 10:34:20 AM~!~Error~!~Script error in file: myip.txt: 5:Invalid procedure call or argument: 'Mid' in line 23

            Any Ideas?

            *'``'*:-.,_,.-:*'``'*:-Fit4Life-:*'``'*:-.,_,.-:*'``'*

            Comment


              #7
              That's got me baffled. Mid is a perfectly valid function. Re-post your current version of the script. Maybe something else is causing the problem.

              Mitch

              http://www.midondesign.com
              http://www.midondesign.com

              Comment


                #8
                This code works here:
                [code]
                Dim ip_url
                Dim page
                Dim pos
                Dim ip


                redundancy = hs.ping("216.177.17.147")
                If redundancy &gt; 0 Then
                hs.WriteLog "Error", "No ping reply from http://checkip.dyndns.org"
                hs.SetDeviceString "z4", "&lt;img src='icons/devices/unreachable.gif' align=absmiddle&gt; WAN IP N/A", True
                Exit Sub
                End If


                ip_url = "http://checkip.dyndns.org"

                page = hs.GetUrl(ip_url, "", False, 80)

                pos = InStr(page, "Current IP Address:") + 20

                lenip = InStr(pos + 1, page, Chr(10)) - pos + 1

                ip = Mid(page, pos, lenip)

                'hs.WriteLog "Info","Current WAN IP: " &ip
                hs.SetDeviceString "z4", "&lt;img src='icons/devices/alive.gif' align=absmiddle&gt; Current WAN IP:" & ip, True

                -Rupp
                💁‍♂️ Support & Customer Service 🙋‍♂️ Sales Questions 🛒 Shop HomeSeer Products

                Comment


                  #9
                  Once Again, Thanks Rupp.

                  That worked...

                  *'``'*:-.,_,.-:*'``'*:-Fit4Life-:*'``'*:-.,_,.-:*'``'*

                  Comment


                    #10
                    Not sure why you'd be asking someone else for your ip address. You can get it from homeseer..
                    The following example works even for machines with multiple adapters.. it excludes the common private ip address ranges 127, 10, 192.168 ..(ouch there's a class B range that should be excluded too but I don't remember it off hand)

                    Option Explicit

                    Sub Main()
                    dim ipaddress,i,ip,ipnet1,ipnet2

                    ipaddress = hs.getipaddress
                    for i=1 to 5
                    ip = hs.stringitem(ipaddress,i," ")
                    if ip = "" then exit for
                    ipnet1 = hs.stringitem(ip,1,".")
                    ipnet2 = hs.stringitem(ip,2,".")
                    if ipnet1 = "127" or ipnet1 = "10" or (ipnet1 = "192" and ipnet2 = "168") then
                    ip = ""
                    else
                    exit for
                    end if
                    next
                    hs.writelog "test", "'"&ip&"'"

                    End Sub

                    Comment


                      #11
                      The reason for the outside site for the IP address is HomeSeer gets all local IP addresses. If you are behind a NAT'ed router then you need an outside source to pole for you live IP address.

                      *'``'*:-.,_,.-:*'``'*:-Fit4Life-:*'``'*:-.,_,.-:*'``'*

                      Comment


                        #12
                        been running my HS machine as a router for so long forgot about those.. In that situation I'd use the http or snmp interface to your router to get your ip.

                        Comment


                          #13
                          something better

                          Originally posted by Rupp View Post
                          This code works here:
                          [code]
                          Dim ip_url
                          Dim page
                          Dim pos
                          Dim ip


                          redundancy = hs.ping("216.177.17.147")
                          If redundancy &gt; 0 Then
                          hs.WriteLog "Error", "No ping reply from http://checkip.dyndns.org"
                          hs.SetDeviceString "z4", "&lt;img src='icons/devices/unreachable.gif' align=absmiddle&gt; WAN IP N/A", True
                          Exit Sub
                          End If


                          ip_url = "http://checkip.dyndns.org"

                          page = hs.GetUrl(ip_url, "", False, 80)

                          pos = InStr(page, "Current IP Address:") + 20

                          lenip = InStr(pos + 1, page, Chr(10)) - pos + 1

                          ip = Mid(page, pos, lenip)


                          'hs.WriteLog "Info","Current WAN IP: " &ip
                          hs.SetDeviceString "z4", "&lt;img src='icons/devices/alive.gif' align=absmiddle&gt; Current WAN IP:" & ip, True

                          -Rupp

                          Very good code to check if internet connection is online.I use the code to reboot router if the internet connection is down (checking the value if it is 0 or 1).
                          A better code that i use by the way and works with no errors always...change the bold with:

                          Separator1 = "Current IP Address:"
                          Separator2 = "&lt;/body&gt;&lt;/html&gt;"
                          Track = Trim(hs.stringitem(page ,2,Separator1))
                          ip = Trim(hs.stringitem(Track,1,Separator2))
                          Attached Files
                          Last edited by stamatis; October 20, 2013, 04:47 PM.

                          Comment

                          Working...
                          X