- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- TCP Socket connection checking.
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2001 09:39 AM
12-03-2001 09:39 AM
Does anyone know of a reliable and preferably easy method of checking port status from within a script. I know this can be done from telneting to a port, although automating it from a script seems to produce mixed results.
I've routed out some C code that sounds like it would do the trick perfectly, although it doesn't want to compile and I could write all I know about C on the back of a postage stamp.
Any pointers, tips suggestions warmly received (as ever!!)
Cheers,
-ChaZ-
#include
#include
#include
#include
#define DEST_IP "1.1.1.1" // changed IP
#define DEST_PORT 1022
int main()
{
int sockfd;
struct sockaddr_in dest_addr; // will hold the destination addr
sockfd = socket(AF_INET, SOCK_STREAM, 0); // do some error checking!
dest_addr.sin_family = AF_INET; // host byte order
dest_addr.sin_port = htons(DEST_PORT); // short, network byte order
dest_addr.sin_addr.s_addr = inet_addr(DEST_IP);
memset(&(dest_addr.sin_zero), '\0', 8); // zero the rest of the struct
// don't forget to error check the connect()!
connect(sockfd, (struct sockaddr *)&dest_addr, sizeof(struct sockaddr));
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2001 10:30 AM
12-03-2001 10:30 AM
Re: TCP Socket connection checking.
"A utility for port scanning large networks. It works fine for single hosts. It incorporates virtually every scanning technique, but specifically it supports TCP connect scanning, TCP SYN and FIN (stealth), bounce attack scanning, ICMP and ping scanning and yet more ... "
http://hpux.cs.utah.edu/hppd/hpux/Networking/Admin/nmap-2.53/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2001 10:56 AM
12-03-2001 10:56 AM
Solutionecho "^]close" | telnet IP.ADD.OF.HOST PORT
status=$?
#status = 0 means host is listening on TCP port PORT
#status = 1 means host port is closed on that host.
by the way, in order to generate the telnet escape character, you have to use:
ctrl+v followed by ctrl+]
it is not visible on a command line but in vi it will show as an ^]
good luck.
BTW I am assuming that the status checking you want done is to determine wheather or not it is listening on the port right? this does not necessarily mean that the daemon is DOING what it is supposed to.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2001 12:15 PM
12-03-2001 12:15 PM
Re: TCP Socket connection checking.
Thanks again,
-ChaZ-
Ps. I'm well versed in the art of NMAP, although our network boys and security auditors aren't keen on having the app freely availible on our production servers!!! - Thanks all the same!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2001 03:10 PM
12-03-2001 03:10 PM
Re: TCP Socket connection checking.
Socket connections can be determined by running netstat -an, it will show udp and tcp information as well. This may be a suitable option for some to telneting to a port, plus you can check udp traffic.
C
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2001 03:16 PM
12-03-2001 03:16 PM
Re: TCP Socket connection checking.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2001 08:14 AM
12-04-2001 08:14 AM
Re: TCP Socket connection checking.
Thanks for the additional comments, Christopher, - sorry, I should have made my question clearer, I had no objection to telnet other than I didn't want to pipe seperate files into the command to get it to check the ports (bit messy) the GURU style ctrl key combo was exactly what I was after! - Thanks for your comments though!
Craig, cheers, netstat -an is okay locally, but this was for a remote checking exercise, so the telnet option is a better bet. Again thanks for the support!!
Cheers,
-ChaZ-