리눅스에서 ip 충돌시 사용자에게 알려 주기[질문]

andro000의 이미지

윈도우즈에서 ip설정 후, 부팅시에 같은 ip가 네트웍상에서 사용됩니다. 라는
충돌 메세지를 사용자에게 가르쳐 주는것을 볼 수 있을 겁니다.

리눅스에서도 마찬가지로 하나의 네트워크 상에 같은 ip를 설정 돼었을 시에 ip 충돌이 났다고 가르쳐 줄 수 있는 방법, 루틴 없을까요?

버그소년의 이미지

답변이 없어 간단히 제 생각을 올려보겠습니다.

ARP를 모니터링하고 있으면 될듯 합니다.

inetd에서 처리해주는게 모범답안일듯 한데...

아무튼.. ARP패킷을 모니터링하고있다가 ARP_REQUEST의 IP가 해당 리눅스이면,

IP충돌로 간주하여 메세지를 뿌리면....

윈도우를 대상으로 스푸핑된 ARP를 쏘니까 IP충돌났다고 뜨네요..

(리눅스는 다른 사람들과 같이 사용하는터라 맘대로 테스트를 못하겠네요. ^^)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/if_ether.h>
#include <netinet/ether.h>
#include <arpa/inet.h>

#pragma pack ( 1 )


struct arp_req
{
    unsigned char sender_mac[6];
    unsigned long sender_ip;
    unsigned char req_mac[6];
    unsigned long req_ip;
    unsigned char padding[48];
};

void ParseARP ( char *buff )
{
    struct in_addr in;
    struct ether_header *eh = (struct ether_header *) buff;
    struct arphdr *arph = (struct arphdr *) ( buff + sizeof ( *eh ) );

    struct arp_req *my_req = (struct arp_req *) ( buff + sizeof ( *eh ) + sizeof ( *arph ) );

    switch ( ntohs ( arph->ar_op ) )
    {
        case ARPOP_REQUEST :
            printf ("ARP REQUEST : ");
            break;
        case ARPOP_REPLY :
            printf ("ARP REPLY : ");
            break;;
        case ARPOP_RREQUEST :
            printf ("ARP RREQUEST : ");
            break;
        case ARPOP_RREPLY :
            printf ("ARP RREQLY : ");
            break;
        default :
            printf ("Unknown ARP OP[%x] : ", ntohs ( arph->ar_op ) );
            break;
    }

    printf ("Ether : SHOST : %s, ", ether_ntoa ( (struct ether_addr *) eh->ether_shost ) );
    printf ("DHOST :%s\n", ether_ntoa ( (struct ether_addr *) eh->ether_dhost ) );

    printf ("MAC[%-17s] : ", ether_ntoa ( (struct ether_addr *) my_req->sender_mac ) );
    in.s_addr = my_req->sender_ip;
    printf ("IP[%-15s] : ", inet_ntoa ( in ) );
    printf ("MAC[%-17s] : ", ether_ntoa ( (struct ether_addr *) my_req->req_mac ) );
    in.s_addr = my_req->req_ip;
    printf ("IP[%-15s] : \n", inet_ntoa ( in ) );
}


int main ( int argc, char **argv )
{
    int sock_fd;
    int recv_len;
    char send_buff[1024] = { '\0' };
    char recv_buff[1024];
    struct sockaddr address;
    struct ether_header *eh;

    if ( ( sock_fd = socket ( PF_PACKET, SOCK_PACKET, htons ( ETH_P_ALL ) ) ) < 0 )
    {
        perror ("socket fail ");
        return 1;
    }

    memset ( &address, 0x00, sizeof ( address ) );
    strncpy ( address.sa_data, "eth0", sizeof ( address.sa_data ) );

    while ( 1 )
    {
        memset ( recv_buff, 0x00, sizeof ( recv_buff ) );
        if ( ( recv_len = read ( sock_fd, recv_buff, sizeof ( recv_buff ) ) ) < 0 )
        {
            perror ("recv fail ");
            break;
        }

        eh = (struct ether_header *) recv_buff;

        switch ( ntohs ( eh->ether_type ) )
        {
            case ETHERTYPE_ARP :
                ParseARP ( recv_buff );
                break;
            default :
                break;
        }
    }

    close ( sock_fd );

    return 0;
}

다른기능들이 포함된 코드에서 해당사항만 추려봤습니다.

컴파일이 되지 않을수도...

ParseARP부분에서 ARPOP_REQUEST이고, sender_ip가 자신의

IP로 전송되는것이 있으면 IP충돌로 간주하면 될듯합니다.

가끔은 밥을 굶어도 살 수 있다.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.