port scanning - How should I do to check if the service running on a remote host? -
i'm writing port scanner , want verify if specific port running standard service expected on port, such ssh
, http
. know 1 of methods send query port , analyze returned information. example, ssh sends me version information upon connection. however, when did connect()
port 22 on ip address, got error number: 110. error message: connection timed out
. idea appreciated.
the whole code long story. paste excerpt here.
struct sockaddr_in dest_addr; dest_addr.sin_family = af_inet; dest_addr.sin_port = htons(22); dest_addr.sin_addr.s_addr = inet_addr("8.8.8.8"); int service_sock = socket(af_inet, sock_stream, ipproto_tcp); if (service_sock < 0) { printf("error creating service socket. error number: %d. error message: %s\n", errno, strerror(errno)); exit(0); } int dest_addr_len = sizeof(dest_addr); if (connect(service_sock, (struct sockaddr *)&dest_addr, dest_addr_len) < 0) { // stuck here printf("error connection. error number: %d. error message: %s\n", errno, strerror(errno)); exit(0); }
to clarify question, need show example. figured out method verify http
service. send string "get / http\n\n"
destination address. call recv()
function read returned message. can this.
http/1.0 400 bad request content-type: text/html; charset=utf-8 content-length: 1419 date: tue, 02 dec 2014 05:56:25 gmt server: gfe/2.0 ...
i can read http
version 1.0
first line.
here want check many services on remote host including not limited ssh
, http
. don't think guessing idea. need general method retrieve information dest_addr
.
ok, need answer own question. got verification work , wrote post it.
Comments
Post a Comment