'목록하단 광고 치환자(withSeok)
728x90

내부 IP 주소 확인

1
2
3
4
import socket
 
in_address=socket.gethostbyname(socket.gethostname())
print(in_address)
 
 

 

1
2
3
4
5
import socket
 
in_address=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
in_address.connect(("www.google.co.kr",443))
print(in_address.getsockname()[0])
cs

 

외부 IP 주소 확인

 

1
2
3
4
5
6
7
import requests
import re
 
req=requests.get("http://ipconfig.kr")
out_address=re.search(r'IP Address : (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})',req.text)[1]
print(out_address)
 
 
 

 

 

내부 IP, 외부 IP 주소 확인

1
2
3
4
5
6
7
8
9
10
11
12
import socket
import requests
import re
 
in_address=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
in_address.connect(("www.google.co.kr",443))
print("내부 IP : ",in_address.getsockname()[0])
 
req=requests.get("http://ipconfig.kr")
out_address=re.search(r'IP Address : (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})',req.text)[1]
print("외부 IP : ",out_address)
 
cs

 

728x90

+ Recent posts