Thread: How to test if port (23) is open on a device

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    13

    How to test if port (23) is open on a device

    Hi
    Somewhat of a newbie...so bear with me.
    Trying to telnet or ssh to a device, so I need to find out which port is open (both maybe) in order to system() afterwards...
    I would like to do this in C, even tho perl has Net::Telnet::cisco and ::SSH too, but will probably get hammered for this !
    Also, how do I send characters to a program spawned by system() ?

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    I need to find out which port is open (both maybe) in order to system() afterwards...
    You'll need to do some socket programming. Beej's guide is a great socket programming resource:
    http://beej.us/guide/bgnet/output/ht...age/bgnet.html

    Also, how do I send characters to a program spawned by system() ?
    Check out popen(). Use it instead of system().
    If you understand what you're doing, you're not learning anything.

  3. #3
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by Mikey View Post
    Hi
    Somewhat of a newbie...so bear with me.
    Trying to telnet or ssh to a device, so I need to find out which port is open (both maybe) in order to system() afterwards...
    I would like to do this in C, even tho perl has Net::Telnet::cisco and ::SSH too, but will probably get hammered for this !
    Also, how do I send characters to a program spawned by system() ?
    Why not just use nmap? It's designed for this purpose.

  4. #4
    Registered User
    Join Date
    Apr 2007
    Posts
    13

    Nocando on Socket programming

    NoCanDo on that programming...not enuf time, the goal can easily be accomplished by a port scanner, but I'd -really like to put it in my 'beginners' C program as findport(port#) which would work off a list in a text file possibly. I'm using Watcom free C, and might be better off using perl but C is just so cool, so do-anything...

  5. #5
    Registered User kryptkat's Avatar
    Join Date
    Dec 2002
    Posts
    638
    [cough]ping it[/cough]
    meow.

  6. #6
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by kryptkat View Post
    [cough]ping it[/cough]
    meow.
    How would a ping tell you if a specific port is open? The only way to find out is to try to connect to the port.

  7. #7
    Day Dreamer
    Join Date
    Apr 2007
    Posts
    45
    Go through the man pages for "nmap"
    Will help.

  8. #8
    Registered User
    Join Date
    Apr 2007
    Posts
    13

    Open port 23 is just the beginning

    Hey again, from a newbie to C and perl...
    What I'm starting out to do, is test if 23 (telnet) is open, if it is, then I need to install SSH on a list of cisco boxes, SSH to the box, and if successful, remove telnet via that session, SSH again, and if error=0, disconnect all.
    I've been 'not exactly happy' with perl...Net::Telnet::Cisco etc etc... Seems everyone has a compiler (or what is it exactly, does anyone really know ?) and the whole perl 'thing' is so disorganized, some things work, some don't, "some they will, some they won't, and some it's just as well".
    I like C more. It seems more exact...like the diff between unix and windoze.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. serial port to poll on request
    By infineonintern in forum C++ Programming
    Replies: 2
    Last Post: 06-11-2009, 06:52 AM
  2. socket newbie, losing a few chars from server to client
    By registering in forum Linux Programming
    Replies: 2
    Last Post: 06-07-2003, 11:48 AM
  3. DOS, Serial, and Touch Screen
    By jon_nc17 in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 01-08-2003, 04:59 PM
  4. Device problem
    By John22 in forum C Programming
    Replies: 0
    Last Post: 12-19-2002, 12:02 PM