• 管理员
    了解作者
  • LINUX
    开发工具
  • 12KB
    文件大小
  • tgz
    文件格式
  • 1
    收藏次数
  • 1 积分
    下载积分
  • 681
    下载次数
  • 2001-01-07 14:45
    上传日期
一个端口扫描器
ipps-1.0.tgz
  • ipps-1.0
  • configure
    727B
  • Makefile
    108B
  • scan.c
    7.5KB
  • TODO
    174B
  • COPYING
    17.6KB
  • CREDITS
    359B
  • README
    4.8KB
内容介绍
/* * IP Port Scanner Version 1.0 * This is a program which scans the ports of a computer to find out * the listening TCP/IP ports. * * Copyright (C) 1999 Victor STANESCU */ /* * This program is free software; You can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your opinion) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Should you need to contact me, the author, you can do so either by * e-mail - mail your message to <bruno@lmn.pub.ro>, or by paper mail * Victor STANESCU, Tineretului 27 Ave., Bl. 18, App. 36, Sect. 4, * Bucharest, ROMANIA. * * For other details, please read the README which should be included in * every distribution of this program. If you do not have this file, please * contact me as specified. */ #include <arpa/inet.h rel='nofollow' onclick='return false;'> #include <netdb.h> #include <netinet/in.h> #include <stdio.h> #include <string.h> #include <stdlib.h> #include <sys/socket.h> #include <sys/types.h> #include <unistd.h> int list_all=0,out_to_file=0; void give_help(char *prgname) { printf("Use: %s hostname||ip_address [options]\n",prgname); printf("Where options are:\n"); printf("\t-b port\t\tBegin scan at this port (default 0)\n"); printf("\t-e port\t\tEnd scan at this port (default 1023)\n"); printf("\t-M mask\t\tThe mask can be either a network mask or\n"); printf("\t\t\t a plain number, specifying the number of 1's at the\n"); printf("\t\t\t left side of the network mask. Thus, a mask of 24\n"); printf("\t\t\t is equivalent with 255.255.255.0. With this option\n"); printf("\t\t\t set, it will scan all the network to whom the\n"); printf("\t\t\t specified machine belongs.\n"); printf("\t-S port\t\tThe source port from which the packets are sent.\n"); printf("\t\t\t It works slower with this option set, as it needs to\n"); printf("\t\t\t wait for the source port to be closed after each\n"); printf("\t\t\t connection.\n"); printf("\t-a\t\tList all ports, as they are scanned, even if they are\n"); printf("\t\t\t closed.\n"); printf("\t-o\t\tOutput to files. For each machine scanned, saves a\n"); printf("\t\t\t file named ip_address.dump.\n"); printf("\n"); } void put_header() { printf("-------------------------------------------\n"); printf(" IPPS 1.0 IP Port Scanner \n"); printf("(C) 1999 Victor STANESCU <bruno@lmn.pub.ro>\n"); printf("-------------------------------------------\n"); } void scan(unsigned int bp, unsigned int ep, unsigned int sport, struct sockaddr_in source, struct sockaddr_in dest) { int sockfd,err,result; unsigned int i; char tmp[20],fname[25],out[50]; struct servent *portname; FILE *ff; if(sport==-1) snprintf(tmp,18,"%s","(unspecified)"); else snprintf(tmp,18,"%d",sport); if(out_to_file) { snprintf(fname,24,"%s.dump",inet_ntoa(dest.sin_addr)); ff=fopen(fname,"wt"); if(!ff) { printf("**ERROR** Could not open file %s\n\n",fname); printf("Seems that you are not allowed to write here.\n"); exit(4); } fprintf(ff,"Scan range: %d -> %d from port %s\n",bp,ep,tmp); fprintf(ff,"Open ports:\n"); } printf("Scanning %s, ports %d:%d, from source port %s.\n",inet_ntoa(dest.sin_addr),bp,ep,tmp); for(i=bp;i<=ep;i++) { sockfd=socket(AF_INET,SOCK_STREAM,0); dest.sin_port=htons(i); if(sport!=-1) { do{ err=bind(sockfd,(struct sockaddr *)&source,sizeof(struct sockaddr)); }while(err); } result=connect(sockfd,(struct sockaddr *)&dest,sizeof(struct sockaddr)); if(result!=-1) { write(sockfd,"quit",4); portname=getservbyport(htons(i),"tcp"); if(portname) snprintf(out,49,"%d\t%s",i,portname->s_name); else snprintf(out,49,"%d",i); printf("\t%s\n",out); if(out_to_file) fprintf(ff,"%s\n",out); } else if(list_all) printf("\t%d\t%s\n",i,"not open"); shutdown(sockfd,2); close(sockfd); } if(out_to_file) fclose(ff); } int main(int argc, char *argv[]) { unsigned int bp=0,ep=1023,noofbits=32,sport=-1; int crt,x=0,netscan=0; struct sockaddr_in source,dest; unsigned long daddr,netmask=0,begip,endip,crtip; struct hostent *dhost; put_header(); if(argc<2) { give_help(argv[0]); exit(0); } if(argc>2) { /* we have some options then */ crt=2; while(crt<argc) { switch(argv[crt][1]) { case 'b': crt++; bp=atoi(argv[crt]); if(bp<0 || bp rel='nofollow' onclick='return false;'>65535) { printf("**ERROR** Not a valid begin port: %u\n",bp); exit(3); } crt++; break; case 'e': crt++; ep=atoi(argv[crt]); if(ep<0 || ep>65535) { printf("**ERROR** Not a valid end port: %u\n",ep); exit(3); } crt++; break; case 'a': list_all=1; crt++; break; case 'o': out_to_file=1; crt++; break; case 'M': crt++; if(strchr(argv[crt],'.')) { netmask=inet_addr(argv[crt]); for(crtip=ntohl(netmask)^0xFFFFFFFF,noofbits=0;crtip;crtip=(crtip>>1),noofbits++); noofbits=32-noofbits; } else { /*we have a plain number*/ noofbits=atoi(argv[crt]); if( noofbits<0 || noofbits>32 ) { printf("**ERROR** Not a valid netmask\n"); exit(3); } if(!noofbits) { printf("SCANNING THE INTERNET !\n"); } netmask=0; for(x=1;x<=noofbits;x++) netmask+=(1<<(32-x)); netmask=htonl(netmask); } crt++; netscan=1; break; case 'S': crt++; sport=atoi(argv[crt]); if(sport<0 || sport>65535) { printf("**ERROR** Not a valid source port: %u\n",sport); exit(3); } { int uid,suid; uid=getuid(); suid=geteuid(); if( (sport<1024)&&uid&&geteuid ) { printf("Only root can bind to ports 0:1023.\n"); printf("You may use as source port only a number from 1024:65535 range.\n"); exit(2); } } crt++; break; default: printf("**ERROR** Could not understand option %s\n",argv[crt]); give_help(argv[0]); exit(3); break; } } } /* getting destination addres */ daddr=inet_addr(argv[1]); if(daddr==-1) { printf("Resolving hostname %s ...",argv[1]); fflush(NULL); /* if it fails to resolve, print something right now */ dhost=gethostbyname(argv[1]); if(dhost==NULL) { herror("gethostbyname"); exit(1); } printf("OK\n"); printf(" # %s -> %s\n",argv[1],inet_ntoa(*((struct in_addr *)dhost->h_addr))); printf("------------------------\n"); daddr=((struct in_addr *)dhost->h_addr)->s_addr; } /* setting the dest structure */ dest.sin_family=AF_INET; source.sin_family=AF_INET; source.sin_addr.s_addr=htonl(INADDR_ANY); if(sport!=-1) source.sin_port=htons(sport); else source.sin_port=htons(0); bzero( &(dest.sin_zero),8); bzero( &(source.sin_zero),8); /*scanning*/ if(netscan) { begip=ntohl(netmask&daddr)+1; endip=begip; for(x=0;x<32-noofbits;x++) endip+=(1<<x); for(crtip=begip;crtip<=endip;crtip++) { dest.sin_addr.s_addr=htonl(crtip); scan(bp,ep,sport,source,dest); } } else { dest.sin_addr.s_addr=daddr; scan(bp,ep,sport,source,dest); } return 0; }
评论
    相关推荐
    • linux扫描仪驱动源码
      linux 扫描仪驱动源码 linux scanner device driver 大家看看
    • linux 扫描器 linux 扫描器
      linux 下的一个扫描器 基于TCP/IP 具体看代码
    • LINUX编程白皮书(pdf非扫描版)
      本书对Linux操作系统及其编程作了整体的介绍,以支持用于开发软件的公开源码模型。对内存管理、进程及其通信机制、PCI、内核模块编程及内核系统结构作了详细的解释,且附有很多程序代码实例。对深入研究Linux下的...
    • 主机脆弱点扫描器
      适用于Linux下的主机安全扫描器,如果要在Windows下运行,则需要修改代码编码
    • hp4600:适用于 Linux 的 HP4600 扫描仪软件
      适用于 Linux 的基本 HP4600 扫描仪软件 这个软件很牛。 我的意思是它实际上没有任何选项,只是将命令作为一种黑匣子魔术咒语重播,以从 HP4600 扫描仪生成 600dpi 彩色扫描。 没有校准,没有别的。 该软件由两个...
    • scanmem:适用于Linux的内存扫描器
      在多次扫描过程之后,scanmem会隔离变量的位置,并允许您修改其值。 图形用户界面 GameConqueror是scanmem的GUI前端,提供更多功能,例如: 灵活的搜索语法 更容易和多变量锁定 更好的过程查找 内存浏览器/编辑...
    • sonarqube-alpine:Alpine Linux中的Sonar Qube + Sonar扫描仪
      sonarqube-alpine:Alpine Linux中的Sonar Qube + Sonar扫描仪
    • 基于linux的条码扫描器例程
      基于linux的开发板,条码扫描器为串行接口,使用qt编写(串口部分使用的C语言)。
    • PhpCms木马扫描器
      PhpCms木马扫描器是独立运行程序,可用于任何PHP程序(其他程序在正确设置特征函数和特征代码后也可使用)木马扫描 安装说明: 请把压缩包中的scan文件夹上传到服务器中 linux用户请把data目录设置777权限 请...
    • PHPCMS木马扫描器 v1.0
      请把压缩包中的scan文件夹上传到服务器中 linux用户请把data目录设置777权限 请修改config.php中的用户名和密码