Skip to main content
Participant
March 26, 2008
Question

Pinging ports

  • March 26, 2008
  • 2 replies
  • 534 views
Hi all, first post

In a nutshell, I have a script which embeds an IP camera's stream into a web page.
I'd like to be able to put some code at the start of the script which can determine whether the camera is on or off (if the script runs while the camera is off everything crashes ).

To reach the camera you use the IP address and port number it's located on; xxxx.xxxx.xxxx.xxxx: xxxx. I wondered if cf can check whether a port is open or closed so it would be possible to determine if the camera's on or off. Maybe it's not possible and I'm just being too hopeful
    This topic has been closed for replies.

    2 replies

    Participating Frequently
    March 26, 2008
    Nice trick! :)
    Inspiring
    March 26, 2008
    m0rtimer wrote:
    > open or closed so it would be possible to determine if the camera's on or off.
    > Maybe it's not possible and I'm just being too hopeful

    see what this does.

    <cfscript>
    try {
    socket=CreateObject("java", "java.net.Socket");
    readerObj=createObject("java","java.io.InputStreamReader");
    bufferedObj=createObject("java","java.io.BufferedReader");
    hostIP=javacast("string", "xxxxx"); // your remote host goes here
    dayTimePort=javacast("int",25);
    socket.init(hostIP, dayTimePort);
    socket.setSoTimeout(1000); // some reasonable timeout value
    inReader=readerObj.init(socket.getInputStream());
    bReader=bufferedObj.init(inReader);
    isAlive=true;
    // check that box
    tStamp=bReader.readLine();
    ServerIP = socket.toString();
    ServerPort = socket.getPort(); // really?
    socket.close();
    if (isAlive)
    writeoutput("server #serverIP# (#serverPort#) is alive at #tStamp#");
    } // try
    catch (Any e) {
    socket.close();
    isAlive=false;
    writeoutput("server #hostIP# (#dayTimePort#) is dead as a doorknob at #now()#");
    }
    </cfscript>

    m0rtimerAuthor
    Participant
    March 26, 2008
    Hi Paul,
    Thanks for the quick response.
    I've been playing with that script and it does kinda do the job, would it be possible for you to explain the scrip in more detail?

    Now I do sound like a complete newb...
    Thanks again,
    Nick