Self-Improvement

Python Requests 모듈의 HTTPS/HTTP 구분 본문

프로그래밍/Python

Python Requests 모듈의 HTTPS/HTTP 구분

JoGeun 2020. 7. 16. 10:45

코드

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import requests
 
= requests.Session()
https_check=Https_Check(target, port,s)
url=https_check+"://"+target+":"+port
s.get(url, verify=False)
 
def Https_Check(target, port,s):
        try:
                resp=s.get('http://%s:%s' %(target,port))
                if resp.status_code==400:
                        return 'https'
                else:
                        return 'http'
        except requests.exceptions.ConnectionError as e:
                return 'https'
        except:
                return 'http'      
cs