/*
* 文件: rtable.cpp
* 描述: 利用IP助手管理路由表示例程序,制台应用程序
* 时间: 2006.3.1
*/
//说明:ip助手管理路由表
#include "stdafx.h"
#include <WinSock2.h>
#include <Windows.h>
#include <IPHlpApi.h>
#include <iostream>
#include <iomanip>
#include <conio.h>
#pragma comment( lib, "Iphlpapi.lib" )
#pragma comment( lib, "Ws2_32.lib" )
using namespace std ;
//************************************
//void showInformation( void ) ;
void Usage( void );
//*************************************
void showRouteTable( void ) ;
void deleteRouteTableItem( _TCHAR* index ) ;
void addRouteTableItem( _TCHAR* tcDest ,
_TCHAR* tcMask ,
_TCHAR* tcGateway ,
_TCHAR* tcInter , _TCHAR*
tcMetric ) ;
int _tmain( int argc, _TCHAR* argv[ ] )
{
WSAData wsadata ;
if ( WSAStartup( MAKEWORD( 1, 1 ) , &wsadata ) )
{
cout << "socket error!" << endl ;
return 0 ;
}
if ( argc == 2 || argc == 3 || argc == 7 )
{
for( int i = 1 ; i < argc ; i++ )
{
if ( argv[ i ][ 0 ] == '-' || argv[i][0] == '/' )
{
switch( argv[ i ][ 1 ] )
{
case 's':
showRouteTable( ) ;
break ;
case 'd':
deleteRouteTableItem( &argv[ ++i ][ 0 ] ) ;
break ;
case 'a':
if ( argc == 7 )
{
addRouteTableItem( &argv[ i+1 ][ 0 ] ,
&argv[ i+2 ][ 0 ] , &argv[ i+3 ][ 0 ] ,
&argv[ i+4 ][ 0 ] ,
&argv[ i+5 ][ 0 ] ) ;
i += 5 ;
}
else
{
cout << "command error!" << endl ;
Usage( ) ;
return 0 ;
}
break ;
case 'h':
case '?':
Usage( ) ;
break ;
default:
cout << "command error!" << endl ;
Usage( ) ;
return 0 ;
}
}
else
{
cout << "command error!" << endl ;
Usage( ) ;
return 0 ;
}
}
}
else
{
cout << "command error!" << endl ;
Usage( ) ;
return 0 ;
}
WSACleanup( ) ;
return 0;
}
void Usage( void )
//**********************************
{
cout << "对本机的路由表进行显示,删除和添加条目操作." << endl ;
cout << "rtable的命令格式是:" << endl ;
cout << endl ;
cout << "rtable -h" << endl ;
cout << "rtable -s" << endl ;
cout << "rtable -d index" << endl ;
cout << "rtable -a Dest Mask Gateway Inter Metric" << endl ;
cout << endl ;
cout << setw( 5 ) << " -h" << "\t\t\t\t\t显示帮助." << endl;
cout << setw( 5 ) << " -s" << "\t\t\t\t\t显示路由表条目." << endl;
cout << setw( 5 ) << " -d" << " index" << "\t\t\t\t删除路由表条目." << endl;
cout << setw( 5 ) << " -a" << " Dest Mask Gateway Inter Metric" << "\t添加路由表条目." << endl ;
cout << endl;
cout << "例如:" << endl ;
cout << " > rtable -h" << "\t\t\t\t\t\t\t" << "...显示帮助" << endl;
cout << " > rtable -s" << "\t\t\t\t\t\t\t" << "...显示路由表" << endl;
cout << " > rtable -d 2" << "\t\t\t\t\t\t" << "...删除第2条目" << endl;
cout << " > rtable -a 192.168.0.12 255.255.255.255 172.16.0.4 1 1" << "\t...添加条目" << endl ;
}
void showRouteTable( void )
{
//Ip地址表:
PMIB_IPADDRTABLE pIpAddrTable;
pIpAddrTable = (PMIB_IPADDRTABLE) GlobalAlloc( GPTR , sizeof(MIB_IPADDRTABLE) );
DWORD dwIpAddrLen = sizeof(MIB_IPADDRTABLE);
if( GetIpAddrTable( pIpAddrTable , &dwIpAddrLen , TRUE ) == ERROR_INSUFFICIENT_BUFFER )
{
GlobalFree( pIpAddrTable ) ;
pIpAddrTable = ( PMIB_IPADDRTABLE ) GlobalAlloc( GPTR , dwIpAddrLen );
}
if ( GetIpAddrTable( pIpAddrTable , &dwIpAddrLen , TRUE ) != NO_ERROR )
{
cout << "show error!" << endl;
GlobalFree( pIpAddrTable );
return ;
}
PMIB_IPFORWARDTABLE pIpForwardTable ;
pIpForwardTable = ( PMIB_IPFORWARDTABLE ) GlobalAlloc( GPTR , sizeof( MIB_IPFORWARDTABLE ) ) ;
DWORD dwSize = sizeof( MIB_IPFORWARDTABLE ) ;
if( GetIpForwardTable( pIpForwardTable , &dwSize , TRUE ) == ERROR_INSUFFICIENT_BUFFER )
{
GlobalFree( pIpForwardTable ) ;
pIpForwardTable = ( PMIB_IPFORWARDTABLE ) GlobalAlloc( GPTR , dwSize ) ;
}
string strIp ,strMask , strGateway , strInterface , strMetric ;
if( GetIpForwardTable( pIpForwardTable , &dwSize , TRUE ) == NO_ERROR )
{
cout << "\n" << setw(2) << "no"
<< setw(16) << "Destination"
<< setw(16) << "mask"
<< setw(16) << "gateway"
<< setw(16) << "interface"
<< setw(8) << "metric"
<< "\n" ;
for( int i = 0 ; i < pIpForwardTable->dwNumEntries ; i++ )
{
in_addr ip ;
ip.S_un.S_addr = pIpForwardTable->table[ i ].dwForwardDest ;
strIp = inet_ntoa( ip ) ;
in_addr Maskip ;
Maskip.S_un.S_addr = pIpForwardTable->table[ i ].dwForwardMask ;
strMask = inet_ntoa( Maskip ) ;
in_addr gatewayip ;
gatewayip.S_un.S_addr = pIpForwardTable->table[ i ].dwForwardNextHop ;
strGateway = inet_ntoa( gatewayip ) ;
for ( int j = 0 ; j < pIpAddrTable->dwNumEntries ; j++ )
{
if ( pIpForwardTable->table[ i ].dwForwardIfIndex ==
pIpAddrTable->table[ j ].dwIndex )
{
if ( pIpAddrTable->table[ j ].dwAddr != 0 )
{
in_addr interfaceip ;
interfaceip.S_un.S_addr = pIpAddrTable->table[ j ].dwAddr;
strInterface = inet_ntoa( interfaceip ) ;
}
else
{
char tmp[ 20 ] ;
ltoa( pIpForwardTable->table[i].dwForwardIfIndex ,
tmp , 20 ) ;
strInterface = tmp ;
}
}
}
cout << setw( 2 ) << i
<< setw( 16 ) << strIp.c_str( )
<< setw( 16 ) << strMask.c_str( )
<< setw( 16 ) << strGateway.c_str( )
<< setw( 16 ) << strInterface.c_str( )
<< setw( 8 ) << pIpForwardTable->table[i].dwForwardMetric1
<< "\n" ;
}
}
else
{
cout << "show error!" << endl ;
GlobalFree( pIpForwardTable ) ;
GlobalFree( pIpAddrTable ) ;
return ;
}
}
void deleteRouteTableItem( _TCHAR* index )
{
int nindex = atoi( index ) ;
PMIB_IPFORWARDTABLE pIpForwardTable ;
DWORD dwSize = 0 ;
DWORD dwRetVal = 0 ;
pIpForwardTable = (MIB_IPFORWARDTABLE*) GlobalAlloc( GPTR , sizeof(MIB_IPFORWARDTABLE) ) ;
if ( GetIpForwardTable( pIpForwardTable, &dwSize, 0 ) == ERROR_INSUFFICIENT_BUFFER )
{
GlobalFree( pIpForwardTable );
pIpForwardTable = (MIB_IPFORWARDTABLE*) GlobalAlloc( GPTR , dwSize) ;
}
if ((dwRetVal = GetIpForwardTable(pIpForwardTable, &dwSize, 0)) == NO_ERROR)
{
if ( nindex < 0 || nindex >= pIpForwardTable->dwNumEntries )
{
cout << "\nIndex error!\n" ;
GlobalFree( pIpForwardTable ) ;
return ;
}
if ( DeleteIpForwardEntry( &pIpForwardTable->table[nindex]) != NO_ERROR)
cout << "\nDelete route table item fail!\n" ;
}
GlobalFree( pIpForwardTable ) ;
}
void addRouteTableItem( _TCHAR* tcDest , _TCHAR* tcMask , _TCHAR* tcGateway , _TCHAR* tcInter , _TCHAR* tcMetric )
{
PMIB_IPFORWARDROW pRoute ;
DWORD nSize = sizeof(MIB_IPFORWARDROW) ;
pRoute = (PMIB_IPFORWARDROW)GlobalAlloc( GPTR , nSize ) ;
pRoute->dwForwardDest = inet_addr(tcDest) ;
pRoute->dwForwardIfIndex = atol(tcInter) ;
pRoute->dwForwardMask = inet_addr(tcMask) ;
pRoute->dwForwardMetric1 = atol(tcMetric) ;
pRoute->dwForwardNextHop = inet_addr(tcGateway) ;
pRoute->dwForwardAge = 10000 ;
pRoute->dwForwardMetric2 = 1 ;
pRoute->dwForwardMetric3 = 1 ;
pRoute->dwForwardMetric4 = 5 ;
pRoute->dwForwardMetric5 = 3 ;
pRoute->dwForwardNextHopAS = 0 ;
pRoute->dwForwardPolicy = 0 ;
pRoute->dwForwardProto = 3 ;
pRoute->dwForwardType = 0 ;
if ( CreateIpForwardEntry( pRoute ) != NO_E
没有合适的资源?快使用搜索试试~ 我知道了~
TCP/IP网络协议仿真教学系统(通用版)课件
共855个文件
htm:521个
gif:200个
jpg:83个
5星 · 超过95%的资源 需积分: 46 68 下载量 104 浏览量
2011-03-04
09:10:48
上传
评论 4
收藏 8.3MB RAR 举报
温馨提示
TCP/IP网络协议仿真教学系统(通用版)课件,完整演示了所有各网络协议的功能。
资源推荐
资源详情
资源评论
收起资源包目录
TCP/IP网络协议仿真教学系统(通用版)课件 (855个子文件)
im1.bmp 392KB
im2.bmp 392KB
im4.bmp 359KB
im3.bmp 352KB
im5.bmp 350KB
d10.bmp 202KB
css.css 961B
an2bg.gif 91KB
s2.gif 37KB
http2.gif 31KB
s3.gif 29KB
Link State Update.gif 28KB
igmpaddr.gif 16KB
udp_checkout.gif 16KB
s16.gif 15KB
O17_1.gif 15KB
rip2.gif 15KB
a3.gif 14KB
filetransfersserver.gif 14KB
igmppac.gif 14KB
rip.gif 14KB
O17_2.gif 12KB
http.gif 12KB
smtp_header_format.gif 11KB
snmpp.gif 10KB
TF13_1.gif 10KB
dhcp1.gif 9KB
dhcp.gif 9KB
filetransfersclient.gif 9KB
chat.gif 9KB
TF13_3.gif 9KB
getsysinfo.gif 8KB
rtable.gif 8KB
1.gif 8KB
mutil.gif 8KB
e_mail.gif 8KB
dhcpshadow.gif 8KB
ftpdownloadclient.gif 8KB
dhcp3.gif 7KB
dhcp2.gif 7KB
mib.gif 7KB
ping.gif 7KB
dhcp4.gif 7KB
TF13_2.gif 6KB
httplittle.gif 6KB
O17_3.gif 6KB
tcpfinish.gif 5KB
httpdownloadclient.gif 5KB
mL2.gif 4KB
mL1.gif 4KB
mL4.gif 4KB
O17_7.gif 4KB
mL3.gif 4KB
mL4a.gif 4KB
mL2a.gif 4KB
mL1a.gif 4KB
left_05a.gif 4KB
left_05.gif 4KB
left_02.gif 4KB
mL3a.gif 4KB
left_04.gif 4KB
left_02a.gif 4KB
left_06.gif 4KB
left_03.gif 4KB
left_04a.gif 4KB
left_07a.gif 4KB
left_09.gif 4KB
left_09a.gif 4KB
left_07.gif 4KB
menu4.gif 4KB
left_03a.gif 4KB
y.gif 4KB
pop3_work.gif 4KB
left_06a.gif 4KB
left_01a.gif 4KB
left_01.gif 4KB
left_08a.gif 4KB
left_08.gif 4KB
menu1.gif 4KB
menu3.gif 3KB
menu2.gif 3KB
smtp_message_format.gif 3KB
smtp_work.gif 3KB
O17_5.gif 3KB
O17_6.gif 3KB
O17_4.gif 3KB
m15_1.gif 2KB
m15_1a.gif 2KB
m17a.gif 1KB
m17.gif 1KB
m08.gif 1KB
m08a.gif 1KB
m13_1a.gif 1KB
m13_1.gif 1KB
3_01_clip_image002.gif 1KB
m14_3.gif 1KB
m14_3a.gif 1KB
m01a.gif 1KB
m02.gif 1KB
m02a.gif 1KB
共 855 条
- 1
- 2
- 3
- 4
- 5
- 6
- 9
资源评论
- 一帆20002018-07-23非常实用的仿真软件 对于学习TCP/IP协议有很大帮助
- cqupt5222013-12-27很强大、很实用,唯一我觉得如果能够提高的地方就是,用仿真软件实现的话,会让人觉得更理想。
mikadokevin
- 粉丝: 11
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功