snmp test
来源:互联网 发布:钢丝野猪吊脚套锁淘宝 编辑:程序博客网 时间:2024/06/12 22:21
// snmp_test.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include <stdlib.h>//#include <windows.h>#include <winsock2.h>#pragma comment(lib, "Ws2_32.lib")#define MAXLENT 1000TCHAR* g_strfilePath; TCHAR* g_strIpAddress; int g_nTimes = 0; int g_nInterval = 0;void usage() { printf("usage: [-f:str] [-i:IP address] [-l:number] [-t:number]\n\n");printf(" -f The file you want to send\n");printf(" -x Witch ip you want to send to\n");printf(" -l The time between two transmission\n");printf(" -t how much times you want to transmit file\n");ExitProcess(1);} void ValidateArgs(int argc,TCHAR ** argv){int i;if (argc < 5) {usage();}for (i=1;i<argc;i++){if((argv[i][0]=='-')||(argv[i][2]== NULL)){switch(tolower(argv[i++][1])){case 'f':if (argv[i]) {g_strfilePath = argv[i];} else {usage();}break;case 'i':if (argv[i]) {g_strIpAddress = argv[i];} else {usage();}break;case 'l':if (argv[i]) {g_nInterval = _ttoi(argv[i]);} else {usage();}break;case 't':if (argv[i]) {g_nTimes = _ttoi(argv[i]);} else {usage();}break;default:usage();break;}} else {usage();break;}}}int _tmain(int argc, _TCHAR* argv[]) { SOCKET sock = 0; WORD wVersionRequested = 0; WSADATA wsaData; int nErr = 0; sockaddr_in addrto; HANDLE hFile = NULL; LPOFSTRUCT lpOpstruct = NULL; DWORD dwMaxLen; DWORD dwLen; char *buf = new char[1000];char *ipbuf; ValidateArgs(argc, argv);if (0 == g_nInterval ) {g_nInterval = 1000;}if (0 == g_nTimes) {g_nTimes = 1;}dwMaxLen = MAXLENT;hFile = CreateFile(g_strfilePath, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,0);if(!hFile) { wprintf(L"file not exist!"); } if(!ReadFile(hFile, (LPVOID)buf,dwMaxLen, &dwLen, NULL) || dwLen == 0) { wprintf(L" file read failed!"); }wVersionRequested = MAKEWORD(2,2); nErr = WSAStartup(wVersionRequested, & wsaData); if (0 != nErr) { wprintf(L"Socket 2.2 init failed!"); return nErr; }if (LOBYTE( wsaData.wVersion ) != 2 || HIBYTE( wsaData.wVersion ) != 2 ) { WSACleanup();CloseHandle(hFile);return 0; } sock = socket( AF_INET, //UDP,TCP, etc SOCK_DGRAM, //UDP type IPPROTO_UDP //protocol ); if (INVALID_SOCKET == sock ) { wprintf(L"Socket create failed!");WSACleanup();return 0; } int cCharacters = int(wcslen(g_strIpAddress)+1);int cbAnsi = cCharacters*2;ipbuf = new char[cbAnsi];memset(&addrto,0,sizeof(addrto)); WideCharToMultiByte(CP_ACP,0, g_strIpAddress,cCharacters,ipbuf,cbAnsi, NULL, NULL);addrto.sin_family = AF_INET; addrto.sin_port = htons(162);addrto.sin_addr.s_addr = inet_addr(ipbuf);while (g_nTimes--) {Sleep(g_nInterval);if (sendto(sock, buf, dwLen, 0, (sockaddr*)&addrto, sizeof(addrto)) == SOCKET_ERROR) {nErr = WSAGetLastError();wprintf(L"WSAGetLastError = %d ", nErr);break;}}closesocket(sock);WSACleanup();CloseHandle(hFile);return 0; }
- snmp test
- SNMP Agent Test with AdvenNet Agent Tester
- snmp client down, yum 卡在transaction test
- net-snmp(5.7.2) install and test in linux
- SNMP
- SNMP
- SNMP
- SNMP
- SNMP
- SNMP
- snmp
- SNMP
- SNMP
- SNMP
- SNMP
- SNMP
- SNMP
- SNMP
- Delphi TdxDBGrid 使用简介
- dos界面实现贪吃蛇
- vfork 和fork
- 关闭应用(自杀,杀别人)
- 如何在Android平台上使用USB Audio设备
- snmp test
- 算法竞赛入门经典第二章笔记
- 内容解析者相关
- 数据库杂记
- oracle 所有等待事件
- screen 闪屏、回滚、vim退出回滚残留问题
- v$session 和v$process 、v$transaction
- CUDA简介
- Oracle之课程实验三(格式化报表)