2025-05-25

와이파이핫스팟 인터넷 활성화.wifi hotsopt internet enable

우분투22.04에서 와이파이핫스팟을 했는데. 연결된 클라이언트들이 인터넷이 안된다.
이유를 gpt에 물어봤더니. 보안상 masquerade와 forwarding을 drop시켰다.
이것들을 동작시 활성화 하도록 스크립트를 추가한다.

sudo mkdir -p /etc/NetworkManager/dispatcher.d

sudo vi /etc/NetworkManager/dispatcher.d/90-hotspot-nat.sh
#!/bin/bash

IFACE="$1"
STATUS="$2"

# 핫스팟 인터페이스명(수정 필요할 수도 있음)
HOTSPOT_IF="wlp0s20f3"

# 유선인터페이스 자동 탐색
eth_if=$(ip -o link show | awk -F': ' '{print $2}' | grep -E '^en' | grep -v 'br' | grep -v 'docker' | grep -v 'veth' | grep -v 'lo' | head -n1)

if [ "$IFACE" = "$HOTSPOT_IF" ] && [ "$STATUS" = "up" ]; then
    # NAT 추가 (중복 X)
    if ! iptables -t nat -C POSTROUTING -s 10.42.0.0/24 -o $eth_if -j MASQUERADE 2>/dev/null; then
        iptables -t nat -A POSTROUTING -s 10.42.0.0/24 -o $eth_if -j MASQUERADE
    fi
    # FORWARD 체인 정책 허용
    iptables -P FORWARD ACCEPT
fi

nmcli con modify Hotspot wifi-sec.key-mgmt wpa-psk
nmcli con modify Hotspot wifi-sec.pmf default
#nmcli con down Hotspot && nmcli con up Hotspot

sudo chmod +x /etc/NetworkManager/dispatcher.d/90-hotspot-nat.sh

2025-04-25

[siwg917] 공유기 mac 얻기, arp table에서 확인.



1. arp 요청함수.

#include "lwip/netif.h"
#include "lwip/ip4_addr.h"
#include "lwip/etharp.h"

#define ARP_RETRY_COUNT 10
#define ARP_WAIT_MS 100

void request_and_print_gateway_mac(const sl_net_wifi_client_profile_t *profile, struct netif *netif)
{
ip4_addr_t gateway_ip;
IP4_ADDR(&gateway_ip,
profile->ip.ip.v4.gateway.bytes[0],
profile->ip.ip.v4.gateway.bytes[1],
profile->ip.ip.v4.gateway.bytes[2],
profile->ip.ip.v4.gateway.bytes[3]);

// 1. ARP 요청 전송
if (etharp_request(netif, &gateway_ip) != ERR_OK) {
printf("Failed to send ARP request to gateway\r\n");
return;
}

// 2. ARP 응답 대기 및 MAC 주소 찾기
struct eth_addr *eth_ret;
const ip4_addr_t *resolved_ip;

for (int i = 0; i < ARP_RETRY_COUNT; i++) {
if (etharp_find_addr(netif, &gateway_ip, &eth_ret, &resolved_ip) >= 0) {
printf("Gateway MAC: %02X:%02X:%02X:%02X:%02X:%02X\r\n",
eth_ret->addr[0], eth_ret->addr[1], eth_ret->addr[2],
eth_ret->addr[3], eth_ret->addr[4], eth_ret->addr[5]);
return;
}
osDelay(100); // FreeRTOS 기반 대기
}

printf("Gateway MAC: [Not found in ARP cache after ARP request]\r\n");
}


2. 업데이트된 arp테이블에서 mac 보기. (함수일부)
void display_client_network_info(sl_net_wifi_client_profile_t profile)
{

printf("\r\n=== Wi-Fi Client Network Information ===\r\n");
printf("SSID: %s\r\n", profile.config.ssid.value);
printf("Security: %d\r\n", profile.config.security);

// IP 정보 표시
printf("\r\n--- IP Configuration ---\r\n");
printf("IP Management Mode: %s\r\n",
profile.ip.mode == SL_IP_MANAGEMENT_DHCP ? "DHCP" :
profile.ip.mode == SL_IP_MANAGEMENT_STATIC_IP ? "Static IP" : "Link Local");

if (profile.ip.type & SL_IPV4) {
printf("IPv4 Address: %d.%d.%d.%d\r\n",
profile.ip.ip.v4.ip_address.bytes[0],
profile.ip.ip.v4.ip_address.bytes[1],
profile.ip.ip.v4.ip_address.bytes[2],
profile.ip.ip.v4.ip_address.bytes[3]);

printf("Subnet Mask: %d.%d.%d.%d\r\n",
profile.ip.ip.v4.netmask.bytes[0],
profile.ip.ip.v4.netmask.bytes[1],
profile.ip.ip.v4.netmask.bytes[2],
profile.ip.ip.v4.netmask.bytes[3]);

printf("Gateway: %d.%d.%d.%d\r\n",
profile.ip.ip.v4.gateway.bytes[0],
profile.ip.ip.v4.gateway.bytes[1],
profile.ip.ip.v4.gateway.bytes[2],
profile.ip.ip.v4.gateway.bytes[3]);

// Gateway MAC 주소 표시
struct netif *netif = netif_default; // 또는 Wi-Fi에 해당하는 netif 지정
ip4_addr_t gateway_ip;
struct eth_addr *eth_ret;
const ip4_addr_t *resolved_ip;

IP4_ADDR(&gateway_ip,
profile.ip.ip.v4.gateway.bytes[0],
profile.ip.ip.v4.gateway.bytes[1],
profile.ip.ip.v4.gateway.bytes[2],
profile.ip.ip.v4.gateway.bytes[3]);

if (etharp_find_addr(netif, &gateway_ip, &eth_ret, &resolved_ip) >= 0) {
printf("Gateway MAC: %02X:%02X:%02X:%02X:%02X:%02X\r\n",
eth_ret->addr[0], eth_ret->addr[1], eth_ret->addr[2],
eth_ret->addr[3], eth_ret->addr[4], eth_ret->addr[5]);
} else {
printf("Gateway MAC: [Not found in ARP cache]\r\n");
}
}
}

3. 실행위치
static void application_start(void *argument)
{
UNUSED_PARAMETER(argument);
sl_status_t status;
sl_ip_address_t ip_address = { 0 };
sl_net_wifi_client_profile_t profile = { 0 };
sl_wifi_performance_profile_t performance_profile = { .profile = ASSOCIATED_POWER_SAVE_LOW_LATENCY };
status = sl_net_init(SL_NET_WIFI_CLIENT_INTERFACE, &client_configuration, &wifi_client_context, NULL);
if (status != SL_STATUS_OK) {
printf("Failed to start Wi-Fi Client interface: 0x%lx\r\n", status);
return;
}
printf("Wi-Fi Client interface success\r\n");

#ifdef SLI_SI91X_MCU_INTERFACE
uint8_t xtal_enable = 1;
status = sl_si91x_m4_ta_secure_handshake(SL_SI91X_ENABLE_XTAL, 1, &xtal_enable, 0, NULL);
if (status != SL_STATUS_OK) {
printf("Failed to bring m4_ta_secure_handshake: 0x%lx\r\n", status);
return;
}
printf("m4_ta_secure_handshake Success\r\n");

2025-02-02

[qemu] 실행

DISTRO=nodistro MACHINE=qemuarm source layers/meta-st/scripts/envsetup.sh

runqemu qemuarm

다음에는 간단한 distro를 만들어서 해봐야겠다.

2024-10-10

구글드라이브 wget 다운받는 명령어

구글드라이브의 파일을 링크가있는사람 무조건받기로 해서 공유링크를 복사하여 아래의 "구글드라이브공유링크"에 붙여넣는다. 원하는파일명은적절히 써준다. 

주의: 실행속성은 추가로 변경해주어야한다. chmod a+x 파일명

GDRIVE_LINK="구글드라이브공유링크" && FILE_ID=$(echo $GDRIVE_LINK | sed -n 's#.*d/\([^/]*\)/.*#\1#p') && wget --no-check-certificate "https://drive.google.com/uc?export=download&id=${FILE_ID}" -O 원하는파일명


2024-08-24

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

 #!/bin/bash


# IV와 UserKey를 설정합니다 (아스키 문자열을 그대로 사용).

IV="0123456789abcdef" 

UserKey="0123456789abcdef"


# IV와 UserKey를 16진수로 변환

IV_HEX=$(echo -n "$IV" | hexdump -ve '1/1 "%.2x"')

UserKey_HEX=$(echo -n "$UserKey" | hexdump -ve '1/1 "%.2x"')


# 암호화할 문자열을 설정합니다.

input='to_encryption_plainText'


# 입력 문자열을 임시 파일에 저장합니다.

echo -n "$input" > input.txt


# AES-128-CBC 모드로 암호화하여 결과를 바이너리 파일로 저장

openssl enc -aes-128-cbc -K "$UserKey_HEX" -iv "$IV_HEX" -in input.txt -out encrypted.bin


# 암호화된 파일을 Base64로 인코딩하면서 개행 문자 없이 출력

openssl enc -base64 -A -in encrypted.bin


2024-08-15

2024-04-26

network metric priority



1. 변경할 인터페이스
2. 그것의 gateway와 metric값 취득
3. 변경.(nmcli변경후 재부팅 또는 ip명령으로 기존값 제거)

nmcli con mod <con> ipv4.route-metric <new value>
ip route del default via <gateway ip> metric <old value>

nmcli con mod eth0 ipv4.route-metric 102
ip route del default via 192.168.222.1 metric 100

gitea 설치

깃 서버 wget -O gitea https://dl.gitea.com/gitea/1.22.0/gitea-1.22.0-linux-amd64 chmod a+x gitea ./gitea web github 에서 미러링시에, access token을 넣어야...