저는 Python3에서 소켓을 사용하여 DHCP 서버와 클라이언트를 작성하고 있습니다. 내 고객:
def client(self):
print("DHCP client is starting...\n")
dest = ('<broadcast>', serverPort)
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
s.setsockopt(socket.SOL_SOCKET, 25, str("veth0" + '\0').encode('utf-8'))
#s.bind(('0.0.0.0', clientPort))
print("Send DHCP discovery.")
data = DHCP_client.discover_get();
s.sendto(data, dest)
내 DHCP 서버:
def server(self):
print("DHCP server is starting...\n")
s=socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR,1)
s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST,1)
s.bind(('', serverPort))
dest = ('255.255.255.255', clientPort)
while(True):
data, address = s.recv(65536)
print(data)
하지만 서버에서 요청을 볼 수는 있지만 서버에서 캡처한 메시지는 볼 수 없습니다.sudo tcpdump --interface=veth1 -v
tcpdump: listening on veth1, link-type EN10MB (Ethernet), capture size 262144 bytes
06:32:10.472938 IP (tos 0x0, ttl 64, id 47168, offset 0, flags [DF], proto UDP (17), length 277)
ubuntu.37318 > 255.255.255.255.bootps: BOOTP/DHCP, Request from 00:05:3c:04:8d:59 (oui Unknown), length 249, xid 0x3903f326, Flags [none]
Client-Ethernet-Address 00:05:3c:04:8d:59 (oui Unknown)
Vendor-rfc1048 Extensions
Magic Cookie 0x63825363
DHCP-Message Option 53, length 1: Discover
Requested-IP Option 50, length 4: 192.168.1.100
여기 설정에 문제가 있나요? 왜 recv
아무것도 잡을 수 없는지 모르겠습니다 . 나에게 줄 조언이 있나요?
내가 veth0
만들고 veth1
전달
ip link add veth0 type veth peer name veth1