Python网络编程 - http/https网页获取
Python网络编程 - http/https网页获取
用例:
import socket
def getDataBySocket(url):
sock = socket.socket()
ip_port = (url, 80)
sock.connect(ip_port)
print("建立连接的远程服务器地址:", sock.getpeername())
#发送HPPT请求
sock.send("GET / HTTP/1.1\r\n".encode("utf-8"))
sock.send(("Host: " + url + "\r\n").encode("utf-8"))
sock.send(("\n").encode("utf-8"))
size = 1024
while True:
try:
data = sock.recv(size)
count = len(data)
print("读取数据数量:", count)
if count == 0:
print("读数据完毕")
break
ret = str(data, encoding="utf-8")
print(ret)
except BaseException as exc:
print("发生异常")
break
if __name__ == '__main__':
url = "www.baidu.com"
getDataBySocket(url)
常见端口设置:
service_list = {
21:"FTP",
22:"ssh",
25:"SMTP",
80:"web",
139:"Samba",
143:"IMAP",
161:"SNMP",
389:"Ldap目录访问协议",
443:"https",
445:"Microsoft SMB",
465:"SMTP SSL",
513:"rlogin",
546:"DHCP failover",
873:"rsync",
993:"IMAPS",
1080:"socks proxy",
1194:"OpenVPN",
1352:"Lotus domino",
1433:"MSSQL",
1521:"Oracle default",
2049:"Nfs",
2181:"ZooKeeper",
2375:"Docker",
3306:"MySQL",
3389:"Remote Desktop",
4440:"rundeck",
4848:"GlassFish控制台",
5000:"SysBase/DB2",
5432:"PostgreSQL",
5632:"pcanywhere",
5900:"vnc",
5984:"Apache CouchDB",
6082:"varnish",
6984:"Apache CouchDB SSL",
6379:"Redis",
7001:"weblogic_Server isten port",
7002:"Server Listen SSL Port",
8069:"zabbix",
8080:"web,jboss,tomcat etc..",
8089:"Jboss/Tomcat/Resin",
8083:"influxDB Web admin",
8086:"influxdb HTTP API",
8095:"Atlassian Crowd",
8161:"activemq",
8888:"Jupyter Notebook",
8983:"solr",
9000:"fastcgi",
9043:"VMware ESXI vsphere",
9080:"websphere http",
9083:"Hive default",
9090:"websphere admin",
9200:"Elsaticsearch http",
9300:"Elsaticsearch Node1",
10000:"HiveServer2",
11211:"memcached",
27017:"MongoDB",
50000:"SAP command excute",
50060:"hadoop web",
50070:"hadoop default",
60000:"HBase Master",
60010:"hbase.master.info.bindAddress",
}