반응형
#include "../common/common.c"
#define NAME "net0"
#define UID 999
#define GID 999
#define PORT 2999
void run()
{
unsigned int i;
unsigned int wanted;
wanted = random();
printf("Please send '%d' as a little endian 32bit int\n", wanted);
if(fread(&i, sizeof(i), 1, stdin) == NULL) {
errx(1, ":(\n");
}
if(i == wanted) {
printf("Thank you sir/madam\n");
} else {
printf("I'm sorry, you sent %d instead\n", i);
}
}
int main(int argc, char **argv, char **envp)
{
int fd;
char *username;
/* Run the process as a daemon */
background_process(NAME, UID, GID);
/* Wait for socket activity and return */
fd = serve_forever(PORT);
/* Set the client socket to STDIN, STDOUT, and STDERR */
set_io(fd);
/* Don't do this :> */
srandom(time(NULL));
run();
}
코드
#!/usr/bin/env python
import socket
import struct
IP="172.16.184.152"
PORT=2999
# Create client socket and connect to the IP/PORT
s1 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s1.connect((IP, PORT))
#x Receive data from the server
data = s1.recv(2048)
print data
number = int( data.split("'")[1] )
number_hex = hex(number)
number_le = struct.pack("I", number_le)[0]
number_hex_le2 = hex(number_le2)
print "Original number %s:, in hex format: %s" % (number, number_hex)
print "Little endian number %s:, in hex format: %s" % (number_le2, number_hex_le2)
# Send data to the server
s1.send(number_le)
# Receive data from the server
data = s1.recv(2048)
print data
# Close the socket
s1.close()
반응형
'system' 카테고리의 다른 글
[protostar]net1 (0) | 2020.11.22 |
---|---|
[protostar]배운 부분 정리 (0) | 2020.11.17 |
[protostar]heap3.c (0) | 2020.11.17 |
[protostar]heap2.c (0) | 2020.11.12 |
[protostar]heap1.c (0) | 2020.11.11 |