7 Replies - 646 Views - Last Post: 11 July 2014 - 05:40 PM Rate Topic: -----

#1 synlight  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 89
  • View blog
  • Posts: 582
  • Joined: 14-September 11

Testing devices for up/down status on external network

Posted 11 July 2014 - 06:33 AM

I know I can use ping internally to test a device's connectivity. What can I use to test devices on another network (assuming ports are forwarded, and their IP addresses are at my disposal)? I was looking into the TCP Client class.. would that also work with devices using DynDNS?
Is This A Good Question/Topic? 0
  • +

Replies To: Testing devices for up/down status on external network

#2 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3664
  • View blog
  • Posts: 11,492
  • Joined: 05-May 12

Re: Testing devices for up/down status on external network

Posted 11 July 2014 - 06:56 AM

What exactly are you trying to monitor?

In my mind, simply having all the copies "phone home" with a heartbeat or pulse signal maybe sufficient. You definitely have to inform your customers that you program phones home, but it will probably be easier to make an outgoing connection than it will be to request that the customer open up ports for you to be able to go in and check on the status of your program.
Was This Post Helpful? 1
  • +
  • -

#3 synlight  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 89
  • View blog
  • Posts: 582
  • Joined: 14-September 11

Re: Testing devices for up/down status on external network

Posted 11 July 2014 - 07:06 AM

Skydiver, I am going to PM you with specifics, confidentiality clause and all :)/>

Short answer: the application is not installed on the target machines. They can be anywhere in the world, and I just need to monitor them for up/down status.

This post has been edited by synlight: 11 July 2014 - 07:13 AM

Was This Post Helpful? 0
  • +
  • -

#4 synlight  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 89
  • View blog
  • Posts: 582
  • Joined: 14-September 11

Re: Testing devices for up/down status on external network

Posted 11 July 2014 - 08:57 AM

Ha!! I did it!! In this example, you could use either variable, ip or dyn, and it will still work.

******NOTE********* improved code at the bottom of the post********************

 string testDynIp = "legitdynaddress.no-ip.org";
            string ip = "59.76.111.55";
            IPAddress  dyn = testDynIp.ToIPAddress();
            TcpClient client = new TcpClient();
            int port = 4000;

            try
            {
                client.Connect(dyn, port);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " " + ex.InnerException);

            }

            if (client.Connected)
            {
                MessageBox.Show("connected");
            }
            else
            {
                MessageBox.Show("not connected");
            }

            client.Close();




And here is the extension class, courtesy of SO.. I forgot to save the link :(/>/>

using System;
using System.Linq;
using System.Net;
using System.Net.Sockets;

namespace Tester
{
    /// <summary>
    /// Basic helper methods around networking objects (IPAddress, IpEndPoint, Socket, etc.)
    /// </summary>
    public static class NetworkingExtensions
    {
        /// <summary>
        /// Converts a string representing a host name or address to its <see cref="IPAddress"/> representation, 
        /// optionally opting to return a IpV6 address (defaults to IpV4)
        /// </summary>
        /// <param name="hostNameOrAddress">Host name or address to convert into an <see cref="IPAddress"/></param>
        /// <param name="favorIpV6">When <code>true</code> will return an IpV6 address whenever available, otherwise 
        /// returns an IpV4 address instead.</param>
        /// <returns>The <see cref="IPAddress"/> represented by <paramref name="hostNameOrAddress"/> in either IpV4 or
        /// IpV6 (when available) format depending on <paramref name="favorIpV6"/></returns>
        public static IPAddress ToIPAddress(this string hostNameOrAddress, bool favorIpV6 = false)
        {
            var favoredFamily = favorIpV6 ? AddressFamily.InterNetworkV6 : AddressFamily.InterNetwork;
            var addrs = Dns.GetHostAddresses(hostNameOrAddress);
            return addrs.FirstOrDefault(addr => addr.AddressFamily == favoredFamily)
                   ??
                   addrs.FirstOrDefault();
        }
    }
}






Played with it a bit. You don't even need the extension method! All of the following variables named "ip" work :)/>

//string ip = "http://legitdynip.no-ip.org:4000";
//string ip = "http://50.11.123.11:200";
//string ip = "http://50.11.123.11";
            string ip = "http://192.168.1.228";
            int port = 80;
            
            Uri baseUri = new Uri(ip);
            port = baseUri.Port;
            string host = baseUri.Host;

            TcpClient client = new TcpClient();

            try
            {
                client.Connect(host, port);
            }



LOL 6 months ago, this would have taken me 2 days.. and I would have been begging you guys for help.

This post has been edited by synlight: 11 July 2014 - 10:00 AM

Was This Post Helpful? 4
  • +
  • -

#5 Curtis Rutland  Icon User is offline

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4577
  • View blog
  • Posts: 8,019
  • Joined: 08-June 10

Re: Testing devices for up/down status on external network

Posted 11 July 2014 - 01:31 PM

It's always great to see people that we've helped to become strong developers in their own right. Our goal has always been to assist people becoming better programmers, not just getting their work done, and it's clear that you've become a significantly better programmer. I'm glad to have helped, and glad you're still here at the forums!
Was This Post Helpful? 2
  • +
  • -

#6 synlight  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 89
  • View blog
  • Posts: 582
  • Joined: 14-September 11

Re: Testing devices for up/down status on external network

Posted 11 July 2014 - 01:44 PM

Thank you, Curtis!! DIC got me through school.. and was there for me when I outpaced my education around month 2 of my career. I've come a long way (been working for a year!), and I still have a lot to learn. But I'm also a lot more confident in my abilities. You guys played no small part in that!!
Was This Post Helpful? 0
  • +
  • -

#7 Curtis Rutland  Icon User is offline

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4577
  • View blog
  • Posts: 8,019
  • Joined: 08-June 10

Re: Testing devices for up/down status on external network

Posted 11 July 2014 - 02:32 PM

Quote

and I still have a lot to learn


Hell, I still have a lot to learn. I've been doing this for about seven years, and every time I learn something new, it reminds me just how much there is out there that I haven't even been exposed to yet. Embrace it, because it'll drive you crazy otherwise. I actually love getting opportunities to learn new stuff.

My advice? Try to answer forum questions that you don't have the answer to off the top of your head. Even if you don't post your answers, solving other people's problems forces you to think about situations that you may have not encountered yet (if ever). Solving them gives you new knowledge that occasionally you can turn around and use in what you're currently working on. I honestly believe I've learned more by helping on forums than from almost any other direct source except work experience.
Was This Post Helpful? 3
  • +
  • -

#8 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3836
  • View blog
  • Posts: 13,587
  • Joined: 12-December 12

Re: Testing devices for up/down status on external network

Posted 11 July 2014 - 05:40 PM

Curtis said:

Even if you don't post your answers..

I did this a lot in the beginning, and still do occasionally. If you are unsure of your answer then you can wait until someone else answers. Hopefully, this confirms your answer, and increases your confidence. Sometimes you will also then find that you can add a little, useful, information to the other person's answer - perhaps clarifying something or adding more detail.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1