티스토리 뷰
(macOS)[python] IP address 확인 : Public/Pravate(Virtual)
jinozpersona 2021. 2. 15. 08:03Intro
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 확인
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
아이피 확인 - 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***
'python > Data Science' 카테고리의 다른 글
(macOS)[python] 파일이름 encoding, 한글 자모분리 해결 (0) | 2022.02.27 |
---|---|
(macOS)[python] 기상청 RSS 서비스를 이용한 데이터 parsing (0) | 2021.02.15 |
(macOS)[python] crawling, scraping, parsing 용어 - 1 (0) | 2021.02.10 |
(macOS)[python] Class : public, protected, private, inheritance (0) | 2020.03.02 |
[Book_Fluent Python] 2장 시퀀스 : 지능형 리스트, 제너레이터 (0) | 2020.02.26 |
- Total
- Today
- Yesterday
- sublime text
- SSH
- 코로나
- pyserial
- Pandas
- Python
- 코로나19
- Django
- git
- MacOS
- github
- CSV
- 자가격리
- analysis
- r
- 확진
- template
- Model
- raspberrypi
- server
- ERP
- Templates
- vscode
- Regression
- DS18B20
- arduino
- COVID-19
- Raspberry Pi
- DAQ
- 라즈베리파이
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |