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

2023-02-28

[docker] portainer

$ docker volume create portainer_data
$ docker run -d -p 8000:8000 -p 9443:9443 --name portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v /data/portainer:/data portainer/portainer-ce:latest

2023-02-27

[docker] maclvan

1. macvlan을 생성한다.
MACVLAN_PARENT_INTERFACE=enx047bcb5e8b20
MACVLAN_SUBNET=192.168.25.0/24
MACVLAN_GATEWAY=192.168.25.1
docker network create -d macvlan   --subnet=$MACVLAN_SUBNET   --gateway=$MACVLAN_GATEWAY   -o parent=$MACVLAN_PARENT_INTERFACE   macvlan_network

#고정IP
docker run -itd --name=macvlan_container --network=macvlan_network --ip=192.168.25.100 --mac-address=00:11:22:33:44:55 hello:0.1

#자동IP
docker run -it --name=macvlan_container --network=macvlan_network --mac-address=00:11:22:33:44:55 hello:0.1


[BLE] 다이소 ble모듈 리눅스에 연결시... 해결법.

[46864.573210] usb 3-3.4.3.4.3: new full-speed USB device number 15 using xhci_hcd
[46864.682163] usb 3-3.4.3.4.3: New USB device found, idVendor=0bda, idProduct=8771, bcdDevice= 2.00
[46864.682171] usb 3-3.4.3.4.3: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[46864.682173] usb 3-3.4.3.4.3: Product: Bluetooth Radio
[46864.682174] usb 3-3.4.3.4.3: Manufacturer: Realtek
[46864.682176] usb 3-3.4.3.4.3: SerialNumber: 00E04C239987
[46864.692638] Bluetooth: hci1: RTL: examining hci_ver=0a hci_rev=000b lmp_ver=0a lmp_subver=8761
[46864.693653] Bluetooth: hci1: RTL: rom_version status=0 version=1
[46864.693660] Bluetooth: hci1: RTL: loading rtl_bt/rtl8761bu_fw.bin
[46864.703096] bluetooth hci1: Direct firmware load for rtl_bt/rtl8761bu_fw.bin failed with error -2
[46864.703106] Bluetooth: hci1: RTL: firmware file rtl_bt/rtl8761bu_fw.bin not found


$ cd /usr/lib/firmware/rtl_bt $ sudo ln -s rtl8761b_fw.bin rtl8761bu_fw.bin


2023-02-17

[팁] ssh접속시 다 보내기.

#접속만 하고싶다. sshpass -p 'P@ssw0rd' ssh -o StrictHostKeyChecking=no root@1.2.3.4 #파일복사 하고싶다. sshpass -p 'P@ssw0rd' scp -o StrictHostKeyChecking=no * root@remotsvr.local:/usr/local/fw/ [원문] https://zetawiki.com/wiki/%EB%A6%AC%EB%88%85%EC%8A%A4_sshpass_%EC%82%AC%EC%9A%A9%EB%B2%95 

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

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