HTTP 프로토콜
HTTP는 클라이언트와 서버 간의 요청-응답 모델을 기반으로 하며, 웹 페이지 데이터 전송에 주로 사용됩니다.
import requests
response = requests.post("http://example.com", data={"key": "value"})
print(response.content)
예제 설명: Python의 requests 라이브러리를 사용하여 POST 요청을 보내고 응답 내용을 받습니다.
HTTPS 프로토콜
HTTPS는 SSL/TLS 암호화를 통해 데이터를 안전하게 전송하는 HTTP의 보안 버전입니다.
import requests
response = requests.post("https://example.com", verify=False, data={"username": "test"})
print(response.status_code)
예제 설명: HTTPS 요청을 통해 사이트에 액세스하고 인증서 검사를 비활성화합니다.
FTP 프로토콜
FTP는 파일을 클라이언트와 서버 간에 전송하기 위한 프로토콜입니다.
from ftplib import FTP
ftp_conn = FTP("ftp.example.com")
ftp_conn.login(user="admin", passwd="12345")
with open("downloaded_file.txt", "wb") as file:
ftp_conn.retrbinary("RETR remote_file.txt", file.write)
ftp_conn.quit()
예제 설명: ftplib를 사용하여 FTP 서버에서 파일을 다운로드합니다.
TCP 프로토콜
TCP는 신뢰할 수 있는 연결 지향 통신을 제공하는 프로토콜입니다.
# 서버 코드
import socket
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_socket.bind(("0.0.0.0", 7777))
server_socket.listen()
client_socket, address = server_socket.accept()
client_socket.sendall(b"Hello from TCP Server")
# 클라이언트 코드
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_socket.connect(("localhost", 7777))
data = client_socket.recv(1024)
print(data.decode())
예제 설명: TCP 서버와 클라이언트 간 기본 통신을 구현합니다.
UDP 프로토콜
UDP는 연결이 필요 없는 신뢰도가 낮은 빠른 전송 프로토콜입니다.
# 서버 코드
import socket
udp_server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
udp_server.bind(("0.0.0.0", 8888))
message, addr = udp_server.recvfrom(1024)
udp_server.sendto(b"Response from UDP Server", addr)
# 클라이언트 코드
udp_client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
udp_client.sendto(b"Test Message", ("localhost", 8888))
response = udp_client.recvfrom(1024)
print(response[0].decode())
예제 설명: UDP 서버와 클라이언트 간 데이터 송수신을 구현합니다.
DNS 프로토콜
DNS는 도메인 이름을 IP 주소로 변환하는 시스템입니다.
nslookup example.com
예제 설명: 명령줄 도구를 사용하여 도메인에 해당하는 IP 주소를 조회합니다.
SSH 프로토콜
SSH는 암호화된 원격 로그인과 명령 실행을 위해 사용됩니다.
import paramiko
ssh_client = paramiko.SSHClient()
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh_client.connect("remotehost", username="user", password="password")
stdin, stdout, stderr = ssh_client.exec_command("whoami")
print(stdout.read().decode())
예제 설명: paramiko 라이브러리를 사용하여 원격 SSH 명령을 실행합니다.
SMTP 프로토콜
SMTP는 이메일을 전송하기 위한 프로토콜입니다.
import smtplib
smtp_server = smtplib.SMTP("smtp.example.com", 587)
smtp_server.starttls()
smtp_server.login("sender@example.com", "password")
smtp_server.sendmail("sender@example.com", "receiver@example.com", "Test email via SMTP")
예제 설명: SMTP를 사용하여 이메일을 전송합니다.
IMAP 프로토콜
IMAP는 메일 서버에서 메일을 읽기 위한 프로토콜입니다.
import imaplib
imap_conn = imaplib.IMAP4_SSL("imap.example.com")
imap_conn.login("user@example.com", "password")
imap_conn.select("inbox")
status, messages = imap_conn.search(None, "ALL")
for num in messages[0].split():
status, msg_data = imap_conn.fetch(num, "(RFC822)")
print(msg_data[0][1])
예제 설명: IMAP를 사용하여 수신함의 메일 목록을 읽습니다.
DHCP 프로토콜
DHCP는 자동으로 IP 주소를 할당하는 프로토콜입니다.
dhclient eth0
예제 설명: 명령줄 도구를 사용하여 네트워크 인터페이스에 대한 동적 IP 설정을 요청합니다.
WebSocket 프로토콜
WebSocket은 클라이언트와 서버 간 실시간 쌍방향 통신을 지원합니다.
const connection = new WebSocket("ws://example.com/socket");
connection.onmessage = (event) => {
console.log(`Received: ${event.data}`);
};
connection.send("Hello WebSocket");
예제 설명: 브라우저에서 WebSocket을 사용하여 실시간 통신을 구축합니다.
MQTT 프로토콜
MQTT는 가벼운 IoT 통신 프로토콜입니다.
import paho.mqtt.client as mqtt
def on_message(client, userdata, message):
print(f"Received: {message.payload.decode()}")
mqtt_client = mqtt.Client()
mqtt_client.on_message = on_message
mqtt_client.connect("mqtt.eclipseprojects.io", 1883)
mqtt_client.subscribe("topic/test")
mqtt_client.loop_forever()
예제 설명: Python을 사용하여 MQTT 토픽을 구독하고 장시간 연결을 유지합니다.
ICMP 프로토콜
ICMP는 네트워크 장치 간 오류 및 제어 메시지를 전달하는 프로토콜입니다.
ping example.com
예제 설명: ping 명령을 사용하여 대상 호스트의 도달 가능성을 테스트합니다.
ARP 프로토콜
ARP는 IP 주소를 물리 MAC 주소로 매핑합니다.
arp -a
예제 설명: 로컬 ARP 캐시 표를 확인하고 IP-MAC 주소 매핑을 표시합니다.
Telnet 프로토콜
Telnet은 평문 원격 로그인을 위한 프로토콜이며, 보안이 취약하여 점차 SSH로 대체되고 있습니다.
telnet example.com 23
예제 설명: Telnet을 사용하여 대상 호스트의 23번 포트에 연결합니다.
RDP 프로토콜
RDP는 Windows 시스템의 그래픽 원격 제어를 위한 프로토콜입니다.
xfreerdp /v:192.168.1.100 /u:user
예제 설명: xfreerdp 도구를 사용하여 RDP 프로토콜로 Windows 호스트에 원격 접속합니다.
SNMP 프로토콜
SNMP는 네트워크 장치를 감시하고 관리하는 데 사용됩니다.
from pysnmp.hlapi import *
errorIndication, errorStatus, errorIndex, varBinds = next(
getCmd(SnmpEngine(),
CommunityData('public'),
UdpTransportTarget(('demo.snmplabs.com', 161)),
ContextData(),
ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysName', 0)))
for varBind in varBinds:
print(f"{varBind}")
예제 설명: Python의 pysnmp 라이브러리를 사용하여 장치의 시스템 이름 정보를 조회합니다.
NTP 프로토콜
NTP는 시스템 시간을 동기화하기 위한 프로토콜입니다.
import ntplib
ntp_client = ntplib.NTPClient()
response = ntp_client.request('pool.ntp.org')
print(ntp_client.from_timestamp(response.tx_time))
예제 설명: NTP 서버로부터 현재 정확한 시간을 가져옵니다.
RTSP 프로토콜
RTSP는 스트림 미디어 서버를 제어하는 프로토콜입니다.
ffmpeg -rtsp_transport tcp -i rtsp://example.com/live.sdp -c:v copy -c:a copy output.mp4
예제 설명: ffmpeg 도구를 사용하여 RTSP 프로토콜로 실시간 스트림을 받아 로컬 파일로 저장합니다.
BGP 프로토콜
BGP는 인터넷 핵심 라우팅 프로토콜로, 자율 시스템(AS) 간 라우팅을 관리합니다.
exabgp --debug /etc/exabgp.conf
예제 설명: ExaBGP 도구를 사용하여 BGP 세션을 구성하고 디버깅합니다.
TLS/SSL 프로토콜
TLS/SSL은 통신에 암호화 및 인증을 제공하며, HTTPS의 하위 계층에서 의존됩니다.
import ssl
import socket
context = ssl.create_default_context()
with socket.create_connection(("example.com", 443)) as sock:
with context.wrap_socket(sock, server_hostname="example.com") as secure_sock:
secure_sock.sendall(b"GET / HTTP/1.1\r\nHost: example.com\r\nConnection: close\r\n\r\n")
response = secure_sock.recv(1024)
print(response.decode())
예제 설명: TLS 암호화를 통해 서버와 안전한 연결을 수립하고 HTTP 요청을 보냅니다.