E D R , A S I H C RSS

Memo

unicode('배','utf-8', 'replace').encode('euc-kr')

우리 은행 495-156526-02-001 (남상협)

http://www.freenetpages.co.uk/hp/alan.gauld/tutintro.htm

http://search.costcentral.com/search?p=Q&srid=S9-3&lbc=costcentral&ts=custom&w=ThinkPad&uid=975848396&method=and&isort=price&srt=150

http://dojeun.egloos.com/315019/

여름인데 놀러갈래!

마지막 사진의 진실은...?
Upload:ReadMe.txt


/*
Packet Sniffer
12.10.02
Made By KT

RFC 768 User Datagram Protocol
RFC 791 Internet Protocol
RFC 792 Internet Control Message Protocol
RFC 793 Transmission Control Protocol
*/


#define MAX_PACKET_SIZE 65525
#define BIND2IP "165.194.17.76"  //Put you'r IP in her

#include <stdio.h>
#include <winsock2.h>
#include <mstcpip.h>
#include <ws2tcpip.h>

typedef struct iphdr
{
	unsigned char VerIHL; //Version and IP Header Length
	unsigned char Tos;
	unsigned short Total_len;
	unsigned short ID;
	unsigned short Flags_and_Frags; //Flags 3 bits and Fragment offset 13 bits
	unsigned char TTL;
	unsigned char Protocol;
	unsigned short Checksum;
	unsigned long SrcIP;
	unsigned long DstIP;
	//unsigned long Options_and_Padding;
} IpHeader;

typedef struct port
{
	unsigned short SrcPort;
	unsigned short DstPort;
} TcpUdpPort;

void ProcessPacket(char* Buffer, int Size)
{
	IpHeader *iphdr;
	TcpUdpPort *port;
	struct sockaddr_in SockAddr;
	unsigned short iphdrlen;
	char C;

	iphdr = (IpHeader *)Buffer;

	iphdrlen = (iphdr->VerIHL << 4);
	memcpy(&C, &iphdrlen, 1);
	iphdrlen = (C >> 4) * 4; //20


	memset(&SockAddr, 0, sizeof(SockAddr));
	SockAddr.sin_addr.s_addr = iphdr->SrcIP;
	printf("Packet From: %s ", inet_ntoa(SockAddr.sin_addr));
	memset(&SockAddr, 0, sizeof(SockAddr));
	SockAddr.sin_addr.s_addr = iphdr->DstIP;
	printf("To: %s ", inet_ntoa(SockAddr.sin_addr));

	switch (iphdr->Protocol)
	{
	case 1:
		printf("Protocol: ICMP ");
		break;
	case 2:
		printf("Protocol: IGMP ");
		break;
	case 6:
		printf("Protocol: TCP ");
		if (Size > iphdrlen)
		{
			port = (TcpUdpPort *)(Buffer + iphdrlen);
			printf("From Port: %i To Port: %i ", ntohs(port->SrcPort), ntohs(port->DstPort));
		}
		break;
	case 17:
		printf("Protocol: UDP ");
		if (Size > iphdrlen)
		{
			port = (TcpUdpPort *)(Buffer + iphdrlen);
			printf("From Port: %i To Port: %i ", ntohs(port->SrcPort), ntohs(port->DstPort));
		}
		break;
	default:
		printf("Protocol: %i ", iphdr->Protocol); 
	}

	printf("n");
}

void StartSniffing(SOCKET Sock)
{
	char *RecvBuffer = (char *)malloc(MAX_PACKET_SIZE + 1);
	int BytesRecv, FromLen;
	struct sockaddr_in From;

	if (RecvBuffer == NULL)
	{
		printf("malloc() failed.n");
		exit(-1);
	}

	FromLen = sizeof(From);

	do
	{
		memset(RecvBuffer, 0, MAX_PACKET_SIZE + 1);
		memset(&From, 0, sizeof(From));

		BytesRecv = recvfrom(Sock, RecvBuffer, MAX_PACKET_SIZE, 0, (sockaddr *)&From, &FromLen);
		
		if (BytesRecv > 0)
		{
			ProcessPacket(RecvBuffer, BytesRecv);
		}
		else
		{
			printf( "recvfrom() failed.n");
		}

	} while (BytesRecv > 0);


	free(RecvBuffer);
}

int main()
{
	WSAData wsaData;
	SOCKET Sock;
	struct sockaddr_in SockAddr;
	DWORD BytesReturned;
	int I = 1;

	try
	{

		if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
		{
			printf("WSAStartup() failed.n");
			exit(-1);
		}

		Sock = socket(AF_INET, SOCK_RAW, IPPROTO_IP);

		if (Sock == INVALID_SOCKET)
		{
			printf("socket() failed.n");
			exit(-1);
		}

		memset(&SockAddr, 0, sizeof(SockAddr));
		SockAddr.sin_addr.s_addr = inet_addr(BIND2IP);
		SockAddr.sin_family = AF_INET;
		SockAddr.sin_port = 0;

		if (bind(Sock, (sockaddr *)&SockAddr, sizeof(SockAddr)) == SOCKET_ERROR)
		{
			printf("bind(%s) failed.n", BIND2IP);
			exit(-1);
		}

		if (WSAIoctl(Sock, SIO_RCVALL, &I, sizeof(I), NULL, NULL, &BytesReturned, NULL, NULL) == SOCKET_ERROR)
		{
			printf("WSAIoctl() failed.n");
			exit(-1);
		}

		StartSniffing(Sock);
	}
	catch (...)
	{
		printf("CRASHn");
	}

	closesocket(Sock);
	WSACleanup();

	return 0;
}
----
위키의 종류 에는
...

이 밖에도 여러가지 언어로 만든 위키가 있다. 매크로를 하나 추가하는 방법이 모두 다르다. 여러 위키에 적용할 수 있는 플러그인을 만들 수 있을까?
----
영어로 말해야 하는 환경을 접하고 답답함을 느끼면 영어공부 해야겠다는 매우 큰 동기가 생긴다.
지금 단어공부가 필요하다.
쓰기 훈련은 NoSmok:영어로일기쓰기를 해야할까? 아직 잘 모르겠다.
svn://zeropage.org/home/SVN/leonardong
htpp://zeropage.org/trac/leonardong/
----
서버
~cpp
from SocketServer import *
import thread
from threading import *

HOST = ('127.0.0.1', 9999)
ClientList = []
bufsize = 1024

class ConnectManager(Thread):
    def __init__(self, conn):
        Thread.__init__(self)
        self.conn = conn
    def run(self):
        print self.conn.getpeername()
        while True:
            try:
                self.conn.send("I'm the Boss")
                data = self.conn.recv(bufsize)
                print data
            except:
                self.conn.close()
                break

class MyServer(BaseRequestHandler):
    def handle(self):
        conn = self.request
        print conn
        if conn:
            connManager = ConnectManager(self.request)
            connManager.start()
            connManager.run()
            ClientList.append(connManager)

    def finish(self):
        print "finished"
    def setup(self):
        print "setup"     
    
if __name__ == "__main__":
    my_server = ThreadingTCPServer(HOST, MyServer)
    my_server.serve_forever()

클라이언트
~cpp
//Project -> Setting -> LINK 메뉴 -> Object/library modules: 의 끝부분에 ws2_32.lib 를 추가한다. 

#include <stdio.h>
#include <winsock2.h>

#define	PORT 9999		 //	서버의 9999번 포트를 연다
#define	BACKLOG	5
#define SERVER_IP "127.0.0.1"

void error(char	*buf)
{
	puts(buf), exit(1);
}

main(){
	WSADATA	wsaData;

	SOCKET server_sock;		   // 서버의 socket을 생성

	SOCKADDR_IN	server_addr;	// 네트워크의 정보를 담을 structure	생성.

	char msg[] = "My name is Na Hwidong,.";
	char question[200];
	int queslen;

	if(	WSAStartup(MAKEWORD(2,2), &wsaData)	== -1 )
		error("WSAStartup Error");


	// socket 설정
	// 프로그래머는	이것을 통해	네트워크와 대화를 한다.

	server_sock	= socket(AF_INET, SOCK_STREAM, 0);
	if(	server_sock	== -1 )
		error("server socket error");


	// 네트웍 정보 설정
	// 이것은 프로그램이 socket과 연결할 정보를	담고있다.

	memset((SOCKADDR_IN	*)&server_addr,	0, sizeof(SOCKADDR_IN));
	// struct sockaddr_in	 ->	   SOCKADDR_IN
	server_addr.sin_family = AF_INET;
	server_addr.sin_addr.s_addr
		= inet_addr(SERVER_IP);	 //	로컬 주소로 설정한다.
	server_addr.sin_port = htons(PORT);


	// 서버에 연결한다. 시도나 해보자.
	if(	connect(server_sock,
			(struct sockaddr *)&server_addr,
			 sizeof(struct	sockaddr)) == -1 )
		fprintf(stderr,	"서버에	connect	할 수 없습니다."), exit(1);	

	
	for( int i = 0 ; i < 3 ; i++ ){

		// 연결하고 뭘 해야지 그냥 있었네..;;
		queslen = recv( server_sock, question, sizeof(question), 0);
		question[queslen] = '';
		printf( "I have to answer the next question. %sn", question);
		if( send(server_sock, msg, sizeof(msg), 0) == -1 )
			fprintf(stderr, "send error"); 
		printf( "I sent an answer. The answer is %srn", msg);
		system("pause");
	}
	WSACleanup();

	exit(0);
	// exit로 종료를 하면 모든 파일	디스크립터를 자동으로 닫고 종료한다.
}

ObserverPattern 연습
신문을 비유로 들면 역할이 두 개로 나뉜다. 한쪽은 신문내용을 원하는 대로 편집하는 신문사, 한쪽은 신문 내용을 제보하는 취재 기자이다.
우리의 취재 기자는 너무나 소명의식이 강하기 때문에 자신이 새로 알게 된 정보를 즉각 신문사에 알린다. 또한 어떤 신문사 쪽에서 기자에게 정보가 틀렸다고 알려주면, 기자는 다른 신문사에게도 모두 새로운 정보를 알려준다.
~cpp
import unittest

class Reporter:
    def __init__(self):
        self.companies = []
        
    def collectNews(self, aNews):
        self.news = aNews
        
    def addCompany(self, anObserverCompany):
        self.companies.append( anObserverCompany )
        
    def notify(self):
        for each in self.companies:
            each.update()
            
class NewsCompany:
    def __init__(self, reporter):
        self.reporter = reporter
        reporter.addCompany(self)
        self.news = ""
        
    def update(self):
        self.news = self.reporter.news

class SportNewsCompany(NewsCompany):
    def __init__(self, reporter):
        NewsCompany.__init__(self,reporter)

class EconomyNewsCompany(NewsCompany):
    def __init__(self, reporter):
        NewsCompany.__init__(self,reporter)

class HanguryeNewsCompany(NewsCompany):
    def __init__(self, reporter):
        NewsCompany.__init__(self,reporter)

    def correctNews(self, aNews):
        self.reporter.collectNews(aNews)
        self.reporter.notify()

       
class TestObserverPattern(unittest.TestCase):
    def testUpdate(self):
        reporter = Reporter()
        company = NewsCompany(reporter=reporter)
        news="He is dead."
        reporter.collectNews(news)
        company.update()
        self.assertEquals( news, company.news )
        
    def testNotify(self):
        reporter = Reporter()
        companies = [SportNewsCompany( reporter ),
                     EconomyNewsCompany( reporter )]
        news="He is dead."
        reporter.collectNews(news)
        reporter.notify()
        for company in companies:
            self.assertEquals( company.news, reporter.news )

class TestCompany(unittest.TestCase):
    def testCorrectNews(self):
        reporter = Reporter()
        companies = [SportNewsCompany( reporter ),
                     EconomyNewsCompany( reporter )]
        theCompany = HanguryeNewsCompany(reporter)
        theCompany.correctNews("He is still alive")
        self.assertEquals( reporter.news, theCompany.news )
        for company in companies:
            self.assertEquals( company.news, reporter.news )

    def xtestTwoRepoter(self):
        reporter = Reporter()
        company = BigNewsCompany(reporter)
        anotherReporter = Reporter()
        anotherReporter.collectNews( "She.." )
        company.hire( anotherReporter )
        anotherReporter.notify()
        self.assertEquals( "She..", company.news )
        reporter.collectNews( "I'm different." )
        reporter.notify()
        self.assertEquals( "I'm different", company.news )
if __name__ == "__main__":
    unittest.main(argv=('','-v'))
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2009-05-27 07:09:19
Processing time 0.0879 sec