项目中要求实现网络拓扑的功能,本想使用SNMP开发的,考虑到项目周期太短了,就找了些网络扫描的文章和代码,整理了一下,来实现这个功能.网络拓扑与网络安全还是有一定距离的,没办法了,时间太紧了,等有时间再考虑SNMP的实现吧.下面是程序的头文件,如果有朋友需要代码,给我留言吧^_^

#include <netinet/ip.h>
#include <netinet/tcp.h>
#include <netinet/udp.h>
#include <netinet/ip_icmp.h>
#define   SYNSCAN          10   /* tcp stealth (syn) scanning */
#define   FINSCAN          20   /* tcp fin scanning */
#define   NULSCAN          30   /* tcp null scanning */
#define   XMASSCAN         40   /* tcp xmas scanning */
#define   SUBSCAN          50   /* tcp subscanning */
#define   CONSCAN          60   /* connect scan - vanilla scan or whatever */
#define   WAIT_SEC          5   /* seconds to wait for an answer */
#define   WAIT_USEC         0   /* useconds nto wait for an answer */
#define   OPEN              2   /* returnvalue for a open port */
#define   CLOSE             3   /* returnvalue for a closed one */
struct pseudohdr {              /* for creating the checksums */
  unsigned long saddr;
  unsigned long daddr;
  char useless;
  unsigned char protocol;
  unsigned short length;
};
struct iptcphdr {               /* read the answers header */
  struct iphdr ip;
  struct tcphdr tcp;           
};
struct ipicmphdr {               /* same here */
  struct iphdr ip;
  struct icmphdr icmp;
};
/*get source ip address*/
unsigned int get_sourceip(void);

/*tcp scan*/
int scantcp(u_int saddr, u_int daddr, unsigned short source,
 int scanmode, int Destination, unsigned char flags, int verbose);

/*udp scan*/
int scanudp(u_int saddr, u_int daddr, unsigned short source, int Destination, int verbose);

/*connect scan*/
int conscan(u_int dest, int Destination);

/*ping host*/
int pinghost(char *ipaddr);

/*sub scan*/
void subscanscan(char *destnet, u_int saddr, unsigned short source);
#endif _LIBPORTSCAN_H