On checking is a port open on the firewall?
Posted
by [email protected]
on Oracle Blogs
See other posts from Oracle Blogs
or by [email protected]
Published on Sun, 02 May 2010 19:34:01 +0100
Indexed on
2010/05/02
19:08 UTC
Read the original article
Hit count: 658
well sometimes DBAs and sysadmin need to check if a particular port is "open" on the corporate firewall
--i.e. *Grid Control* Will the communication between OMS and a management agent work? --
One solution well consist on deploying the piece of software in question, start it and just check if everything works fine, however i find more classy trying to get that information before
There are several tools for doing so --i.e. nmap *like Trinity on The Matrix*, but just found a nice piece of code for establishing a socket on a parameter passed port.
After running the program doing a telnet from the client machine will be a walk in the park
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
int main(int argc, char *argv[])
{
int sockfd, newsockfd, portno, clilen;
char buffer[256];
struct sockaddr_in serv_addr, cli_addr;
int n;
if (argc < 2) {
fprintf(stderr,"ERROR: A
port must be provided. Aborting ...\n");
return 1;
}
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd < 0)
{
fprintf("ERROR: Unable to open
socket. Aborting ...\n");
return 1;
}
portno = atoi(argv[1]);
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = INADDR_ANY;
serv_addr.sin_port = htons(portno);
if (bind(sockfd, (struct sockaddr *)
&serv_addr,sizeof(serv_addr)) < 0)
{
fprintf("ERROR: Unable to bind socket. Aborting ...\n");
return 1;
}
listen(sockfd,5);
clilen = sizeof(cli_addr);
newsockfd = accept(sockfd, (struct sockaddr *)
&cli_addr,&clilen);
if (newsockfd < 0)
{
fprintf("ERROR:
Unable to accept connection. Aborting...\n");
return 1;
}
return 0;
}
Hope it helps
L
© Oracle Blogs or respective owner