Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // system libraries
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- // multithreading libraries
- #include <pthread.h>
- // networking libraries
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <netinet/in.h>
- #include <arpa/inet.h>
- #include <netdb.h>
- // defines
- #define PORT_END_NUMBER 65535
- #define SOCKET_MAIN_THREAD 0
- // globals
- int threads;
- struct sockaddr_in *temp;
- char *ip = "127.0.0.1";
- int port;
- int status[5];
- int port_range[2];
- // future variables
- int global_port;
- int local_port;
- // ! code begin
- void NET_INIT(){
- free(temp);
- status[0] = socket(AF_INET, SOCK_STREAM, 0);
- temp = malloc(sizeof(struct sockaddr_in));
- temp->sin_family = AF_INET;
- temp->sin_addr.s_addr = inet_addr(ip);
- }
- int *ScanPort(char *ip, int port, int *Connect){
- int *C;
- C = malloc(sizeof(int));
- Connect = malloc(sizeof(int));
- temp = NULL;
- free(temp);
- NET_INIT();
- temp->sin_port = htons(port);
- *C = connect(status[SOCKET_MAIN_THREAD], (struct sockaddr*)&temp, sizeof(temp));
- return C;
- }
- int Scan(){
- int NB;
- int *S;
- pthread_t local_id;
- NB = port_range[0];
- while (NB < port_range[1]){
- pthread_create(&local_id, NULL, S = ScanPort(ip, NB, 0), (void *)&local_id);
- printf("ip: %s ; port: %d ; connect() status: %d\n", ip, NB, *S);
- NB++;
- }
- return 0;
- }
- int NewportHelp(){
- printf("newport .1 by unidef\n");
- printf("multithreaded network scanner\n");
- printf("./newport ip port-range-start port-range-end threads\n");
- return 0;
- }
- void Print_Variables(){
- printf("\n*ip = %s\nport_range = %d - %d\nthreads = %d\n", ip, port_range[0], port_range[1], threads);
- return;
- }
- int main(int argc, char *argv[]){
- struct hostent *host;
- long x;
- if (argc != 5){
- printf("beta software, please input right variables\n");
- NewportHelp();
- return 1;
- }
- host = gethostbyname(argv[1]);
- ip = host->h_addr_list;
- port_range[0] = atoi(argv[2]);
- port_range[1] = atoi(argv[3]) + 1;
- threads = atoi(argv[4]);
- printf("data successfully allocated\n");
- printf("starting network scan on %s from port(s) %d to %d using %d threads\n", ip, port_range[0], port_range[1], threads);
- Scan();
- Print_Variables();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement