336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

Windows Network Load Balancing (VirtualBox & Windows2012) #4





Test 를 위한 IIS 설정 및 Test 를 진행 해보겠습니다







1. AppTest1 설정































2. AppTest2 설정





3. Client PC 에서 테스트





이렇게 192.168.20.13 으로 접속을 하면 자동으로 192.168.20.11 혹은 192.168.20.12 로 연결됩니다.










336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

Windows Network Load Balancing (VirtualBox & Windows2012) #3



이제 Windows Network Load Balancing 설정을 해보겠습니다.





이런 형태의 구성이 될 겁니다.







1. AppTest1 에서 Cluster 를 만들기 위해 첫번째 Host 인 192.168.20.11 를 검색 합니다.




 

 

2. 추가된 Host 확인


 

 

 

 

 

 

 

 

 

 

 

 

 



 

 

 

 

 

 

3. Cluster IP 로 사용할 IP를 추가


 

 

 

 

 

 

 


 

 

 

 

 

 

 4. Cluster IP 입력


 

 

 

 

 

 

 



 

 

 

 

 

 

 5. Edit 하여 Cluster Operation Mode 변경

 

 

 

 

 

 

 


 

 

 

 

 

 

 

 6. Port Rules 변경


 

 

 

 

 

 


 

 

 

 

 

 

 

 

 7. Fitering Mode -> Multiple Host : None 선택

 

 

 

 

 


 

 

 

 

 

 

 8. Finish


 

 

 

 

 

 

 


 

 

 

 

 

 9. AppTest1(192.168.20.11)이 Cluster IP(192.168.20.13)으로 설정된 것이 보입니다.


 

 

 

 

 

 

 

 


 

 

 

 

 

 10. AppTest2(192.168.20.12)을 Cluster 에 Host 로 추가해보겠습니다.

 

 

 

 

 

 

 

 


 

 

 

 

 

  11. AppTest2(192.168.20.12)을 검색


 

 

 

 

 

 

 

 


 

 

 

  10. AppTest2(192.168.20.12)을 선택


 

 

 

 

 

 

 

 

 

 


 

 

 

 

  11. IP 확인


 

 

 

 

 

 

 

 

 


 

 

 

 

 

 


 

 

 

 

 

 

 


 

 

 

    12. Port Rule 확인


 

 

 

 

 

 

 

 

 

 


 

 

 

     13. 이제 추가되어 Pending 중 입니다. 


 Virtual Box 라 그런지.... 시간이 좀 걸립니다.







이제 설정은 모두 끝났습니다.







336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

Windows Network Load Balancing (VirtualBox & Windows2012) #2



이제 VirtualBox 의 AppTest1, AppTest2 를 설정해보겠습니다.




1. 공통설정








1.1 Server Manager 를 엽니다.





1.2 Server Manager -> Manage -> Add Roles and Features









1.3 Server Manager -> Manage -> Add Roles and Features -> Features -> Network Load Balacing : Check



1.4 Server Manager -> Manage -> Add Roles and Features -> Server Roles-> Web Server (IIS) : Check




1.5 Network Load Balancing Manager 를 엽니다.





2. AppTest 별 설정



2.1 AppTest1 을 여기까지





2.2 AppTest2 를 여기까지







2.3 AppTest1 의 IP설정을 한번 확인해봅니다


NAT 인터페이스는 자동으로 설정하여 10.0.2.15 를 부여 받았고


호스트 전용 어댑터는 # 1 에서 설정한대로 

IP 주소 : 192.168.20.11

서브넷마스크 : 255.255.255.0

게이트웨이 : 192.168.20.1

기본 설정 DNS 서버 : 192.168.20.1

로 설정합니다.


http://tansanc.tistory.com/entry/Windows-Network-Load-Balancing-VirtualBox-Windows2012-1








2.4 AppTest2 의 IP설정을 한번 확인해봅니다


NAT 인터페이스는 자동으로 설정하여 10.0.2.15 를 부여 받았고


호스트 전용 어댑터는 # 1 에서 설정한대로 

IP 주소 : 192.168.20.12

서브넷마스크 : 255.255.255.0

게이트웨이 : 192.168.20.1

기본 설정 DNS 서버 : 192.168.20.1

로 설정합니다.





336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

Windows Network Load Balancing (VirtualBox & Windows2012) #1 




VirtualBox 를 이용하여 Windows Network Load Balancing 을 테스트 해보려고 합니다.




WNLB 이라고도 부르고 NLB 라고도 부르기도 합니다.







인터넷에 자료가 없는 것은 아니지만.. Virtual Box 로 테스트하는 경우는 잘 없어서


정리해봅니다.





Network Load Balancing Overview

https://msdn.microsoft.com/ko-kr/library/hh831698(v=ws.11).aspx



Overview of Network Load Balancing

https://technet.microsoft.com/en-us/library/cc725691(v=ws.11).aspx





1. Virtual Box 에 Windows 2012 Server 2대를 설치 합니다.










2. AppTest1, AppTest2 로 두 개를 만들었습니다.













3. 네트워크 어댑터 설정을 다음 그림을 참고하여 만들어 주세요.



4.  NAT 어댑터, 호스트 전용 어댑터 각 1개씩으로 설정해줍니다.





AppTest1 설정




AppTest2 설정





4. Virtual Box 를 구동하는 컴푸터의 어댑터 들입니다. 


5. 호스트 전용 어댑터를 Virtual Box Host-Only Ethernet Adapter 에 연결하였으므로 










6. Virtual Box Host-Only Ethernet Adapter 의 IP를 확인하거나 수정해둡니다.


이 어댑터는 Virtual Box AppTest1, Virtual Box AppTest2, Client Computer(VirtualBox를 실행시키고 있는 컴퓨터)간의 통신을 위해 설정하는 것입니다.



저는 


Virtual Box AppTest1 : 

IP 주소 : 192.168.20.11

서브넷마스크 : 255.255.255.0

게이트웨이 : 192.168.20.1

기본 설정 DNS 서버 : 192.168.20.1



Virtual Box AppTest2

IP 주소 : 192.168.20.12

서브넷마스크 : 255.255.255.0

게이트웨이 : 192.168.20.1

기본 설정 DNS 서버 : 192.168.20.1


Client Computer : 

IP 주소 : 192.168.20.1

서브넷마스크 : 255.255.255.0



Load Balancing 을 위한 가상 IP : 192.168.20.13




로 설정 할 것 입니다.





7. 그래야 나중에 Client Computer 에서 테스트를 하는게 편하겠죠










Winpcap Test 05

Programming/C,CPP,CS 2016. 3. 7. 09:56 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

Winpcap Test 04 의  pcap_loop() 대신에 pcap_next_ex()  를 활용해본다.




 

/*

* Copyright (c) 1999 - 2005 NetGroup, Politecnico di Torino (Italy)

* Copyright (c) 2005 - 2006 CACE Technologies, Davis (California)

* All rights reserved.

*

* Redistribution and use in source and binary forms, with or without

* modification, are permitted provided that the following conditions

* are met:

*

* 1. Redistributions of source code must retain the above copyright

* notice, this list of conditions and the following disclaimer.

* 2. Redistributions in binary form must reproduce the above copyright

* notice, this list of conditions and the following disclaimer in the

* documentation and/or other materials provided with the distribution.

* 3. Neither the name of the Politecnico di Torino, CACE Technologies 

* nor the names of its contributors may be used to endorse or promote 

* products derived from this software without specific prior written 

* permission.

*

* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS

* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT

* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR

* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT

* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,

* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT

* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,

* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY

* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT

* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE

* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

*

*/


#include <stdio.h>


#include "pcap.h"


#ifndef WIN32

#include <sys/socket.h>

#include <netinet/in.h>

#else

#include <winsock.h>

#endif



// Function prototypes

void ifprint(pcap_if_t *d);

char *iptos(u_long in);

char* ip6tos(struct sockaddr *sockaddr, char *address, int addrlen);

void packet_handler(u_char *param, const struct pcap_pkthdr *header, const u_char *pkt_data);



int main()

{

pcap_if_t *alldevs;

pcap_if_t *d;

char errbuf[PCAP_ERRBUF_SIZE+1];

char source[PCAP_ERRBUF_SIZE+1] = {'0'};

int inum;

int i = 0;

// Winpcap Test 05

struct pcap_pkthdr *header;

int res;

struct tm ltime;

char timestr[16];

const u_char *pkt_data;

time_t local_tv_sec;



pcap_t *adhandle;



if (pcap_findalldevs_ex(source, NULL, &alldevs, errbuf) == -1)

{

fprintf(stderr,"Error in pcap_findalldevs: %s\n",errbuf);

exit(1);

}


/* Scan the list printing every entry */

for(d=alldevs;d;d=d->next)

{

ifprint(d);

i++;

}


printf("Enter the interface number (1-%d):",i);

scanf_s("%d", &inum);



if(inum < 1 || inum > i)

{

printf("\nInterface number out of range.\n");

/* Free the device list */

pcap_freealldevs(alldevs);

return -1;

}


/* Jump to the selected adapter */

for(d=alldevs, i=0; i< inum-1 ;d=d->next, i++);





/* Open the device */

if ( (adhandle= pcap_open(d->name,          // name of the device

65536,            // portion of the packet to capture

// 65536 guarantees that the whole packet will be captured on all the link layers

PCAP_OPENFLAG_PROMISCUOUS,    // promiscuous mode

1000,             // read timeout

NULL,             // authentication on the remote machine

errbuf            // error buffer

) ) == NULL)

{

fprintf(stderr,"\nUnable to open the adapter. %s is not supported by WinPcap\n", d->name);

/* Free the device list */

pcap_freealldevs(alldevs);

return -1;

}


printf("\nlistening on %s...\n", d->description);


/* At this point, we don't need any more the device list. Free it */

pcap_freealldevs(alldevs);

// Winpcap Test 05

    /* Retrieve the packets */

    while((res = pcap_next_ex( adhandle, &header, &pkt_data)) >= 0){

        

        if(res == 0)

            /* Timeout elapsed */

            continue;

        

        /* convert the timestamp to readable format */

        local_tv_sec = header->ts.tv_sec;

        localtime_s(&ltime, &local_tv_sec);

        strftime( timestr, sizeof timestr, "%H:%M:%S", &ltime);

        

        printf("%s,%.6d len:%d\n", timestr, header->ts.tv_usec, header->len);

    }

    

    if(res == -1){

        printf("Error reading the packets: %s\n", pcap_geterr(adhandle));

        return -1;

    }


return 1;

}




/* Print all the available information on the given interface */

void ifprint(pcap_if_t *d)

{

pcap_addr_t *a;

char ip6str[128];


/* Name */

printf("\tName: %s\n",d->name);


/* Description */

if (d->description)

printf("\tDescription: %s\n",d->description);


/* Loopback Address*/

printf("\tLoopback: %s\n",(d->flags & PCAP_IF_LOOPBACK)?"yes":"no");


/* IP addresses */

for(a=d->addresses;a;a=a->next) {

if(a->addr->sa_family != AF_INET)

continue;


printf("\tAddress Family Name: AF_INET\n");

if (a->addr)

printf("\tAddress: %s\n",iptos(((struct sockaddr_in *)a->addr)->sin_addr.s_addr));

if (a->netmask)

printf("\tNetmask: %s\n",iptos(((struct sockaddr_in *)a->netmask)->sin_addr.s_addr));

if (a->broadaddr)

printf("\tBroadcast Address: %s\n",iptos(((struct sockaddr_in *)a->broadaddr)->sin_addr.s_addr));

if (a->dstaddr)

printf("\tDestination Address: %s\n",iptos(((struct sockaddr_in *)a->dstaddr)->sin_addr.s_addr));

}

printf("\n");

}




/* From tcptraceroute, convert a numeric IP address to a string */

#define IPTOSBUFFERS    12

char *iptos(u_long in)

{

static char output[IPTOSBUFFERS][3*4+3+1];

static short which;

u_char *p;


p = (u_char *)&in;

which = (which + 1 == IPTOSBUFFERS ? 0 : which + 1);

_snprintf_s(output[which], sizeof(output[which]), sizeof(output[which]),"%d.%d.%d.%d", p[0], p[1], p[2], p[3]);

return output[which];

}


char* ip6tos(struct sockaddr *sockaddr, char *address, int addrlen)

{

socklen_t sockaddrlen;


#ifdef WIN32

sockaddrlen = sizeof(struct sockaddr_in6);

#else

sockaddrlen = sizeof(struct sockaddr_storage);

#endif



if(getnameinfo(sockaddr, 

sockaddrlen, 

address, 

addrlen, 

NULL, 

0, 

NI_NUMERICHOST) != 0) address = NULL;


return address;

}


/* Callback function invoked by libpcap for every incoming packet */

void packet_handler(u_char *param, const struct pcap_pkthdr *header, const u_char *pkt_data)

{

struct tm ltime;

char timestr[16];

time_t local_tv_sec;


/*

* unused variables

*/

(VOID)(param);

(VOID)(pkt_data);


/* convert the timestamp to readable format */

local_tv_sec = header->ts.tv_sec;

localtime_s(&ltime, &local_tv_sec);

strftime( timestr, sizeof timestr, "%H:%M:%S", &ltime);


printf("%s,%.6d len:%d\n", timestr, header->ts.tv_usec, header->len);


}


'Programming > C,CPP,CS' 카테고리의 다른 글

Winpcap Test 07  (0) 2016.03.07
Winpcap Test 06  (0) 2016.03.07
Winpcap Test 04  (0) 2016.03.07
Winpcap Test 03  (0) 2016.03.07
Winpcap Test 02  (0) 2016.03.07

Winpcap Test 04

Programming/C,CPP,CS 2016. 3. 7. 09:49 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

응용


02,03 Test 를 합친다.


03 에서의 목록으로는 어떤 디바이스가 내가 캡쳐할 디바이스인지를 구분하기가 어렵다.


02에서의 상세정보를 활용하여 정리한다.



 

/*

* Copyright (c) 1999 - 2005 NetGroup, Politecnico di Torino (Italy)

* Copyright (c) 2005 - 2006 CACE Technologies, Davis (California)

* All rights reserved.

*

* Redistribution and use in source and binary forms, with or without

* modification, are permitted provided that the following conditions

* are met:

*

* 1. Redistributions of source code must retain the above copyright

* notice, this list of conditions and the following disclaimer.

* 2. Redistributions in binary form must reproduce the above copyright

* notice, this list of conditions and the following disclaimer in the

* documentation and/or other materials provided with the distribution.

* 3. Neither the name of the Politecnico di Torino, CACE Technologies 

* nor the names of its contributors may be used to endorse or promote 

* products derived from this software without specific prior written 

* permission.

*

* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS

* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT

* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR

* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT

* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,

* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT

* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,

* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY

* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT

* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE

* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

*

*/


#include <stdio.h>


#include "pcap.h"


#ifndef WIN32

#include <sys/socket.h>

#include <netinet/in.h>

#else

#include <winsock.h>

#endif



// Function prototypes

void ifprint(pcap_if_t *d);

char *iptos(u_long in);

char* ip6tos(struct sockaddr *sockaddr, char *address, int addrlen);

void packet_handler(u_char *param, const struct pcap_pkthdr *header, const u_char *pkt_data);



int main()

{

pcap_if_t *alldevs;

pcap_if_t *d;

char errbuf[PCAP_ERRBUF_SIZE+1];

char source[PCAP_ERRBUF_SIZE+1] = {'0'};

int inum;

int i = 0;

pcap_t *adhandle;



if (pcap_findalldevs_ex(source, NULL, &alldevs, errbuf) == -1)

{

fprintf(stderr,"Error in pcap_findalldevs: %s\n",errbuf);

exit(1);

}


/* Scan the list printing every entry */

for(d=alldevs;d;d=d->next)

{

ifprint(d);

i++;

}


printf("Enter the interface number (1-%d):",i);

scanf_s("%d", &inum);



if(inum < 1 || inum > i)

{

printf("\nInterface number out of range.\n");

/* Free the device list */

pcap_freealldevs(alldevs);

return -1;

}


/* Jump to the selected adapter */

for(d=alldevs, i=0; i< inum-1 ;d=d->next, i++);





/* Open the device */

if ( (adhandle= pcap_open(d->name,          // name of the device

65536,            // portion of the packet to capture

// 65536 guarantees that the whole packet will be captured on all the link layers

PCAP_OPENFLAG_PROMISCUOUS,    // promiscuous mode

1000,             // read timeout

NULL,             // authentication on the remote machine

errbuf            // error buffer

) ) == NULL)

{

fprintf(stderr,"\nUnable to open the adapter. %s is not supported by WinPcap\n", d->name);

/* Free the device list */

pcap_freealldevs(alldevs);

return -1;

}


printf("\nlistening on %s...\n", d->description);


/* At this point, we don't need any more the device list. Free it */

pcap_freealldevs(alldevs);


/* start the capture */

pcap_loop(adhandle, 0, packet_handler, NULL);



return 1;

}




/* Print all the available information on the given interface */

void ifprint(pcap_if_t *d)

{

pcap_addr_t *a;

char ip6str[128];


/* Name */

printf("\tName: %s\n",d->name);


/* Description */

if (d->description)

printf("\tDescription: %s\n",d->description);


/* Loopback Address*/

printf("\tLoopback: %s\n",(d->flags & PCAP_IF_LOOPBACK)?"yes":"no");


/* IP addresses */

for(a=d->addresses;a;a=a->next) {

if(a->addr->sa_family != AF_INET)

continue;


printf("\tAddress Family Name: AF_INET\n");

if (a->addr)

printf("\tAddress: %s\n",iptos(((struct sockaddr_in *)a->addr)->sin_addr.s_addr));

if (a->netmask)

printf("\tNetmask: %s\n",iptos(((struct sockaddr_in *)a->netmask)->sin_addr.s_addr));

if (a->broadaddr)

printf("\tBroadcast Address: %s\n",iptos(((struct sockaddr_in *)a->broadaddr)->sin_addr.s_addr));

if (a->dstaddr)

printf("\tDestination Address: %s\n",iptos(((struct sockaddr_in *)a->dstaddr)->sin_addr.s_addr));

}

printf("\n");

}




/* From tcptraceroute, convert a numeric IP address to a string */

#define IPTOSBUFFERS    12

char *iptos(u_long in)

{

static char output[IPTOSBUFFERS][3*4+3+1];

static short which;

u_char *p;


p = (u_char *)&in;

which = (which + 1 == IPTOSBUFFERS ? 0 : which + 1);

_snprintf_s(output[which], sizeof(output[which]), sizeof(output[which]),"%d.%d.%d.%d", p[0], p[1], p[2], p[3]);

return output[which];

}


char* ip6tos(struct sockaddr *sockaddr, char *address, int addrlen)

{

socklen_t sockaddrlen;


#ifdef WIN32

sockaddrlen = sizeof(struct sockaddr_in6);

#else

sockaddrlen = sizeof(struct sockaddr_storage);

#endif



if(getnameinfo(sockaddr, 

sockaddrlen, 

address, 

addrlen, 

NULL, 

0, 

NI_NUMERICHOST) != 0) address = NULL;


return address;

}


/* Callback function invoked by libpcap for every incoming packet */

void packet_handler(u_char *param, const struct pcap_pkthdr *header, const u_char *pkt_data)

{

struct tm ltime;

char timestr[16];

time_t local_tv_sec;


/*

* unused variables

*/

(VOID)(param);

(VOID)(pkt_data);


/* convert the timestamp to readable format */

local_tv_sec = header->ts.tv_sec;

localtime_s(&ltime, &local_tv_sec);

strftime( timestr, sizeof timestr, "%H:%M:%S", &ltime);


printf("%s,%.6d len:%d\n", timestr, header->ts.tv_usec, header->len);


}


'Programming > C,CPP,CS' 카테고리의 다른 글

Winpcap Test 06  (0) 2016.03.07
Winpcap Test 05  (0) 2016.03.07
Winpcap Test 03  (0) 2016.03.07
Winpcap Test 02  (0) 2016.03.07
Winpcap Test 01  (0) 2016.03.07

Winpcap Test 01

Programming/C,CPP,CS 2016. 3. 7. 08:50 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

Winpcap Test 01



Download WinPcap 4.1.2 Developer's Pack

http://www.winpcap.org/devel.htm



C/C++ -> Genenral -> Additional Include Directories : WpdPack/WpdPack/Include


Linker -> General -> Additional Library Directories : WpdPack/WpdPack/Lib


Linker -> Input -> Addtional Dependencies : wpcap.lib Packet.lib


C/C++ -> Preprocessor -> PreProcessor Definitions : HAVE_REMOTE


sample Code

/* Copyright (c) 1999 - 2005 NetGroup, Politecnico di Torino (Italy)

 * Copyright (c) 2005 - 2006 CACE Technologies, Davis (California)

 * All rights reserved.

 *

 * Redistribution and use in source and binary forms, with or without

 * modification, are permitted provided that the following conditions

 * are met:

 *

 * 1. Redistributions of source code must retain the above copyright

 * notice, this list of conditions and the following disclaimer.

 * 2. Redistributions in binary form must reproduce the above copyright

 * notice, this list of conditions and the following disclaimer in the

 * documentation and/or other materials provided with the distribution.

 * 3. Neither the name of the Politecnico di Torino, CACE Technologies 

 * nor the names of its contributors may be used to endorse or promote 

 * products derived from this software without specific prior written 

 * permission.

 *

 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS

 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT

 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR

 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT

 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,

 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT

 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,

 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY

 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT

 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE

 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

 *

 */



#include <stdlib.h>

#include <stdio.h>


//

// NOTE: remember to include WPCAP and HAVE_REMOTE among your

// preprocessor definitions.

//


#include <pcap.h>


#define LINE_LEN 16


int main(int argc, char **argv)

{   

pcap_if_t *alldevs, *d;

pcap_t *fp;

u_int inum, i=0;

char errbuf[PCAP_ERRBUF_SIZE];

int res;

struct pcap_pkthdr *header;

const u_char *pkt_data;


    printf("pktdump_ex: prints the packets of the network using WinPcap.\n");

    printf("   Usage: pktdump_ex [-s source]\n\n"

           "   Examples:\n"

           "      pktdump_ex -s file://c:/temp/file.acp\n"

           "      pktdump_ex -s rpcap://\\Device\\NPF_{C8736017-F3C3-4373-94AC-9A34B7DAD998}\n\n");


    if(argc < 3)

    {


        printf("\nNo adapter selected: printing the device list:\n");

        /* The user didn't provide a packet source: Retrieve the local device list */

        if (pcap_findalldevs_ex(PCAP_SRC_IF_STRING, NULL, &alldevs, errbuf) == -1)

        {

            fprintf(stderr,"Error in pcap_findalldevs_ex: %s\n", errbuf);

            return -1;

        }

        

        /* Print the list */

        for(d=alldevs; d; d=d->next)

        {

            printf("%d. %s\n    ", ++i, d->name);


            if (d->description)

                printf(" (%s)\n", d->description);

            else

                printf(" (No description available)\n");

        }

        

        if (i==0)

        {

            fprintf(stderr,"No interfaces found! Exiting.\n");

            return -1;

        }

        

        printf("Enter the interface number (1-%d):",i);

        scanf_s("%d", &inum);

        

        if (inum < 1 || inum > i)

        {

            printf("\nInterface number out of range.\n");


            /* Free the device list */

            pcap_freealldevs(alldevs);

            return -1;

        }

        

        /* Jump to the selected adapter */

        for (d=alldevs, i=0; i< inum-1 ;d=d->next, i++);

        

        /* Open the device */

        if ( (fp= pcap_open(d->name,

                            100 /*snaplen*/,

                            PCAP_OPENFLAG_PROMISCUOUS /*flags*/,

                            20 /*read timeout*/,

                            NULL /* remote authentication */,

                            errbuf)

                            ) == NULL)

        {

            fprintf(stderr,"\nError opening adapter\n");

            return -1;

        }

    }

    else 

    {

        // Do not check for the switch type ('-s')

        if ( (fp= pcap_open(argv[2],

                            100 /*snaplen*/,

                            PCAP_OPENFLAG_PROMISCUOUS /*flags*/,

                            20 /*read timeout*/,

                            NULL /* remote authentication */,

                            errbuf)

                            ) == NULL)

        {

            fprintf(stderr,"\nError opening source: %s\n", errbuf);

            return -1;

        }

    }


    /* Read the packets */

    while((res = pcap_next_ex( fp, &header, &pkt_data)) >= 0)

    {


        if(res == 0)

            /* Timeout elapsed */

            continue;


        /* print pkt timestamp and pkt len */

        printf("%ld:%ld (%ld)\n", header->ts.tv_sec, header->ts.tv_usec, header->len);          

        

        /* Print the packet */

        for (i=1; (i < header->caplen + 1 ) ; i++)

        {

            printf("%.2x ", pkt_data[i-1]);

            if ( (i % LINE_LEN) == 0) printf("\n");

        }

        

        printf("\n\n");     

    }


    if(res == -1)

    {

        fprintf(stderr, "Error reading the packets: %s\n", pcap_geterr(fp));

        return -1;

    }


    return 0;

}


'Programming > C,CPP,CS' 카테고리의 다른 글

Winpcap Test 03  (0) 2016.03.07
Winpcap Test 02  (0) 2016.03.07
CPP 2015-01-15 수업내용 정리  (0) 2015.01.15
C 2015-01-09 실습  (0) 2015.01.09
Run-Time Check Failure #3 - The variable 'a' is being used without being initialized.  (0) 2014.05.14

JAVA MYSQL Test

Programming/JAVA,JSP 2013. 4. 27. 17:05 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

JAVA MYSQL Test


1. MYSQL 설치


http://www.mysql.com/downloads/installer/


1.2 MYSQL JAVA 드라이버 설치


http://www.mysql.com/downloads/connector/j/


ZIP 파일 압축 해제 후




jar 파일 을 복사하여


내 컴퓨터의 


Java\jre7\lib\ext


폴더에 붙여넣기 합니다.





2. MYSQL Table 생성


DROP DATABASE book_db;

CREATE DATABASE book_db;

USE book_db;

CREATE TABLE books(

book_id INT NOT NULL auto_increment,

title VARCHAR(50),

publisher VARCHAR(30),

year VARCHAR(10),

price INT,

PRIMARY KEY(book_id)

);


3. TEST CODE





import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class test {
	public static Connection makeConnection() {
		String url = "jdbc:mysql://localhost/book_db";
		String id = "root";
		String password = "green";
		Connection con = null;
		try {
			Class.forName("com.mysql.jdbc.Driver");
			System.out.println("드라이버 적재 성공");
			con = DriverManager.getConnection(url, id, password);
			System.out.println("데이터베이스 연결 성공");
		} catch (ClassNotFoundException e) {
			System.out.println("드라이버를 찾을 수 없습니다.");
		} catch (SQLException e) {
			System.out.println("연결에 실패하였습니다.");
		}
		return con;
	}

	public static void main(String[] args) throws SQLException {
		Connection con = makeConnection();
		Statement stmt = con.createStatement();
		ResultSet rs = stmt.executeQuery("SELECT * FROM books");
		while (rs.next()) {
			int id = rs.getInt("book_id");
			String title = rs.getString("title");
			System.out.println(id + " " + title);
		}
	}
}

3. 데이터베이스 연결 확인




'Programming > JAVA,JSP' 카테고리의 다른 글

MYSQL & REST 실습 코드  (0) 2013.04.28
JAVA MYSQL 활용 1  (0) 2013.04.27
JAVA 코드 그럴듯 하게 보이게 하기?!  (1) 2013.04.27
restlet download restlet-jse-2.1.2  (0) 2013.04.27
RESTLET Point  (0) 2013.04.21