티스토리 뷰

Intro

Public IP Address : 공인아이피, 통신사가 제공하는 main 인터넷 주소

Private(Virtual) IP Address : 사설(가상)아이피, Public IP를 네트워크 중계 기능을 가지는 Router(or modem, 공유기)를 통해 분개하여 제공하는 주소

 

Requirements

 - Editor : sublime text3

 - python 3.9.1

 - requests 2.25.1

 - BeautifulSoup4 4.9.3

 

Download

$ pip install --upgrade pip

pip install beautifulsoup4

pip install requests

 

1. terminal ip address 확인 : lo0, en0, awdl0, llw0, utun0

$ ifconfig | grep inet
inet 127.0.0.1 netmask 0xff000000 : loopback localhost, IPv4 127.0.0.1, IPv6 ::1(0:0:0:0:0:0:0:1의 약자), 로컬 컴퓨터를 원격 컴퓨터인것 처럼 통신할 수 있어 테스트 목적으로 주로 사용

...
inet 192.xxx.xxx.xxx netmask 0xffffff00 broadcast 192.xxx.xxx.255 : en0, ethernet, Router(or 공유기) 제공 사설(or 가상) IP
inet6 --*--%awdl0 : Apple Wireless Direct Link. WIFI p2p connection for things like AirDrop, Airplay, etc. Also used for Bluetooth
inet6 --*--%llw0    : Low-latency WLAN Interface. Used by the Skywalk system
inet6 --*--%utun0 : Tunneling interface. Used for VPN connections to tunnel traffic or for software like Back To My Mac
...

 

 

2. Public ip address 확인

- www.ipify.org

 

ipify - A Simple Public IP Address API

API Usage Using ipify is ridiculously simple. You have three options. You can get your public IP directly (in plain text), you can get your public IP in JSON format, or you can get your public IP information in JSONP format (useful for Javascript developer

www.ipify.org

- www.findip.kr

 

아이피 확인 - my ip address

IP 주소를 확인하는 가장 쉽고 빠른 방법 이 사이트(findip.kr)에 접속하는 것이 IP주소를 확인하는 가장 쉽고 빠른 방법이다. 211.249.218.1 가 현재 접속한 기기의 공인 IP(Internet Protocol) 주소다 IP주소

www.findip.kr

 

3. python code : hostname, lo0, en0 & api를 이용한 public ip 확인

# -*- coding: utf-8 -*-

import socket
import requests
from bs4 import BeautifulSoup as bs


#### ip myPC
myHostName = socket.gethostname()
myIPinfo = socket.gethostbyname_ex(myHostName)

#### public ip
def findIP():
	pubIP1 = requests.get("https://api.ipify.org").text
	res = requests.get('https://api.findip.kr')
	soup = bs(res.text, 'html.parser')
	pubIP2 = soup.select_one('body').getText().split()
	return pubIP2

print("Host Name : {}".format(myHostName))
print("IP lo0 : {}".format(myIPinfo[2][0]))
print("IP en0 : {}".format(myIPinfo[2][1]))
print("My pubIP from api.ipify.org : ", pubIP1)
print("My pubIP from api.findip.kr : ", findIP()[10])

 

--REPL--

Host Name : YOURID.local
IP lo0 : 127.0.0.1
IP en0 : 192.xxx.xxx.xxx
My pubIP from api.ipify.org :  xx.xx.xx.xxx
My pubIP from api.findip.kr :  xx.xx.xx.xxx

***Repl Closed***

 

 

 

반응형
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/07   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
글 보관함