2023-03-28

[GPT] 쓰지않는 ipv6 다 지워버리기.

필요없는 ipv6주소가 자꾸 중복되어 거슬린다. 
삭제해버리자.

#!/bin/bash
for interface in $(ifconfig | grep '^[a-zA-Z0-9]' | awk '{print $1}')
do
    ip -6 addr flush dev $interface
done

스크립트만들고 sudo로 실행.

2023-03-23

u-boot menuconfig 보는곳.

~/work/wrlinux/lts-21/build/tmp-glibc/work/stm32mp153d_ssonic-wrs-linux-gnueabi/u-boot-stm32mp/2020.10.r1-r0/build/stm32mp153d-ssonic_trusted_defconfig# make menuconfig

2023-03-10

인터넷연결 확인방법

단순히 인터넷이 되는지만 확인하고자 한다면,

DNS서버에 접속만 확인한다.

PING은 지연시간까지 표시해주지만 필요없다. 복잡도도 상당하다.

8.8.8.8 주소, 53번포트에 connect만 하여 성공실패여부만 확인하고 끝.

소스는 리눅스에서는 바로되고, 필요한만큼만, 수정해서 쓰자.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <netdb.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>

int main(int argc, char *argv[]) {
if (argc != 3) {
fprintf(stderr, "Usage: %s <hostname> <port>\n", argv[0]);
exit(1);
}

char *hostname = argv[1];
char *port = argv[2];
struct addrinfo hints, *res;
int status, sock;

memset(&hints, 0, sizeof hints);
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;

if ((status = getaddrinfo(hostname, port, &hints, &res)) != 0) {
fprintf(stderr, "getaddrinfo error: %s\n", gai_strerror(status));
exit(1);
}

sock = socket(res->ai_family, res->ai_socktype, res->ai_protocol);

if (connect(sock, res->ai_addr, res->ai_addrlen) == 0) {
printf("Success\n");
} else {
printf("Failed\n");
}

close(sock);
freeaddrinfo(res);
return 0;
}


2023-03-08

[tcp] multicast reciever

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <netinet/in.h>
#include <arpa/inet.h>

#define MULTICAST_ADDR "239.0.0.1"
#define PORT 8888
#define BUFSIZE 1024

int main(int argc, char** argv) {
int sock;
struct sockaddr_in addr;
char buf[BUFSIZE];
int recv_len;
struct ip_mreq mreq;
int enable = 1;

// 멀티캐스트 소켓 생성
sock = socket(AF_INET, SOCK_DGRAM, 0);
if (sock < 0) {
perror("Failed to create socket");
exit(EXIT_FAILURE);
}

// 멀티캐스트 TTL 설정
setsockopt(sock, IPPROTO_IP, IP_MULTICAST_TTL, &enable, sizeof(enable));

// 멀티캐스트 그룹에 참여
mreq.imr_multiaddr.s_addr = inet_addr(MULTICAST_ADDR);
mreq.imr_interface.s_addr = htonl(INADDR_ANY);
setsockopt(sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq));

// 소켓 주소 설정
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = htonl(INADDR_ANY);
addr.sin_port = htons(PORT);

// 소켓 바인드
if (bind(sock, (struct sockaddr*)&addr, sizeof(addr)) < 0) {
perror("Failed to bind socket");
exit(EXIT_FAILURE);
}

// 데이터 수신 및 출력
while (1) {
memset(buf, 0, BUFSIZE);
recv_len = recv(sock, buf, BUFSIZE, 0);
if (recv_len < 0) {
perror("Failed to receive data");
exit(EXIT_FAILURE);
}
printf("Received data: %s\n", buf);
}

// 소켓 닫기
close(sock);

return 0;
}

[udp] multicast send

//// sender
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <netinet/in.h>
#include <arpa/inet.h>

#define MULTICAST_ADDR "239.0.0.1"
#define PORT 8888
#define FILENAME "test.txt"

int main(int argc, char **argv)
{
int sock;
struct sockaddr_in addr;
char buf[1024];
int read_len, send_len, total_len;
FILE *fp;
struct ip_mreq mreq;
int enable = 1;

// 파일 열기
fp = fopen(FILENAME, "r");
if (fp == NULL)
{
perror("Failed to open file");
exit(EXIT_FAILURE);
}

// 멀티캐스트 소켓 생성
sock = socket(AF_INET, SOCK_DGRAM, 0);
if (sock < 0)
{
perror("Failed to create socket");
exit(EXIT_FAILURE);
}

// 멀티캐스트 TTL 설정
setsockopt(sock, IPPROTO_IP, IP_MULTICAST_TTL, &enable, sizeof(enable));

// 멀티캐스트 그룹에 참여
mreq.imr_multiaddr.s_addr = inet_addr(MULTICAST_ADDR);
mreq.imr_interface.s_addr = htonl(INADDR_ANY);
setsockopt(sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq));

// 소켓 주소 설정
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = inet_addr(MULTICAST_ADDR);
addr.sin_port = htons(PORT);

// 파일 읽어서 멀티캐스트로 전송
while ((read_len = fread(buf, 1, sizeof(buf), fp)) > 0)
{
total_len = 0;
while (total_len < read_len)
{
send_len = sendto(sock, buf + total_len, read_len - total_len, 0,
(struct sockaddr *)&addr, sizeof(addr));
if (send_len < 0)
{
perror("Failed to send data");
exit(EXIT_FAILURE);
}
total_len += send_len;
}
}

// 파일과 소켓 닫기
fclose(fp);
close(sock);

return 0;
}

2023-03-01

[nmcli] mac ip match

sudo nmcli connection modify eth0 ipv4.method shared
sudo nmcli connection modify eth0 ipv4.dhcp-client-id "my_client_id"
sudo nmcli connection modify eth0 ipv4.dhcp-timeout 120
sudo nmcli connection modify eth0 ipv4.dhcp-hostname "my_hostname"
sudo nmcli connection modify eth0 ipv4.dhcp-lease-time 3600
sudo nmcli connection modify eth0 ipv4.dhcp-send-hostname yes
sudo nmcli connection modify eth0 ipv4.dhcp-send-client-id yes
sudo nmcli connection modify eth0 ipv4.dhcp-hostname "my_hostname"
sudo nmcli connection modify eth0 +ipv4.dhcp-hostname-mac 00:11:22:33:44:55,192.168.1.50
sudo nmcli connection modify eth0 +ipv4.dhcp-hostname-mac 00:AA:BB:CC:DD:EE,192.168.1.51

암호화 + base64 하고 쉘스크립트.

 #!/bin/bash # IV와 UserKey를 설정합니다 (아스키 문자열을 그대로 사용). IV="0123456789abcdef"  UserKey="0123456789abcdef" # IV와 UserKey를 16...