vpn 차단 자바스크립트 > 코딩 스토리

vpn 차단 자바스크립트

본문

<script>

async function getClientIP() {

    try {

        const response = await fetch('https://api64.ipify.org?format=json');

        const data = await response.json();

        return data.ip;

    } catch (error) {

        console.error('Error fetching client IP:', error);

        return null;

    }

}


async function detectVPNAndRedirect() {

    const ip = await getClientIP();

    if (!ip) {

        console.error('Unable to retrieve IP address.');

        return;

    }


    const apiUrl = `https://api.ipquery.io/${ip}`;


    try {

        const response = await fetch(apiUrl);

        const data = await response.json();


        if (data.risk && (data.risk.is_vpn || data.risk.is_proxy || data.risk.is_tor || data.risk.is_datacenter)) {

            // Redirect VPN/proxy/Tor/datacenter users to block.html

            window.location.href = '/block.html';

        } else {

            console.log(`The IP address ${ip} is not associated with a VPN, proxy, Tor, or datacenter.`);

        }

    } catch (error) {

        console.error('Error while detecting VPN:', error);

    }

}


// Call the function to detect VPN and redirect if necessary

detectVPNAndRedirect();


</script>

좋아요51 이 글을 좋아요하셨습니다
url 복사 카카오톡 공유 라인 공유 페이스북 공유 트위터 공유

카테고리 분류 학습 시스템 (총 0개 학습됨)

예측 카테고리: 스타트업-테크비즈 (랜덤 - 학습 데이터 없음)

이 분류가 맞나요? 학습시켜주세요!

등록된 댓글이 없습니다.

  • RSS
  • _  글쓰기 글쓰기
전체 302건
게시물 검색

접속자집계

오늘
1,602
어제
3,897
최대
42,418
전체
939,830