Sockets Programming with Python: Get the port of a server

IronReign

So as the title suggests is there any way that I can get the port of a website/ip with a socket connection? I assigned socket.gethostbyname() to the simple variable "ip" so that I can print out the result in console but can I do the same with the port? Here is the website that I am using to learn with > https://docs.python.org/3/library/socket.html < and what I am wondering is if this is a good source or does anyone know a better one? Thank you much :D

Daniel

You can get the currently used port with getsockname:

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind(('0.0.0.0', 0))
print('listening on port:', sock.getsockname()[1])

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Sockets Programming with Python: Get the port of a server

From Dev

Port Forwarding, and Python Sockets

From Dev

Python networking programming through sockets

From Java

HTTP Server with python sockets

From Dev

Register clients to server - java sockets programming

From Dev

Errno 111 Connection refused in Python sockets programming

From Dev

Errno 111 Connection refused in Python sockets programming

From Dev

Multi multiplayer server sockets in python

From Dev

Sockets in C(Linux) - How do I get client IP & Port

From Dev

PIC programming - Get value of multiple buttons to a port

From Dev

How to send a message in a specific port with python sockets ? No random ports

From Dev

Connecting to a simple sockets python server remotely

From Dev

Server(Python) - Client(Java) communication using sockets

From Dev

Server host for python raw sockets use

From Dev

Python - Server listening from two UDP sockets

From Dev

Python Sockets - Sending a packet to a server and waiting for a response

From Dev

Python Sockets - Sending a packet to a server and waiting for a response

From Dev

Server(Python) - Client(Java) communication using sockets

From Dev

Unix Domain Sockets C Server and Python Client

From Dev

Programming Python with an EasyPHP server?

From Dev

Programming Python with an EasyPHP server?

From Dev

Cache a HTTP GET REQUEST in Python Sockets

From Dev

How to get the Domain name in Python sockets?

From Dev

How to get html code using python sockets

From Dev

Python socket server/client programming

From Dev

Checking for open ports on a remote server using sockets hangs when the port is closed, C

From Dev

redis-server run multiple times binds multiple listening sockets on the same port?

From Dev

How to get arduino port with python

From Dev

Any Port Issue : Python is hanging at STSConnection().get_session_token In server , But Works fine in my laptop

Related Related

  1. 1

    Sockets Programming with Python: Get the port of a server

  2. 2

    Port Forwarding, and Python Sockets

  3. 3

    Python networking programming through sockets

  4. 4

    HTTP Server with python sockets

  5. 5

    Register clients to server - java sockets programming

  6. 6

    Errno 111 Connection refused in Python sockets programming

  7. 7

    Errno 111 Connection refused in Python sockets programming

  8. 8

    Multi multiplayer server sockets in python

  9. 9

    Sockets in C(Linux) - How do I get client IP & Port

  10. 10

    PIC programming - Get value of multiple buttons to a port

  11. 11

    How to send a message in a specific port with python sockets ? No random ports

  12. 12

    Connecting to a simple sockets python server remotely

  13. 13

    Server(Python) - Client(Java) communication using sockets

  14. 14

    Server host for python raw sockets use

  15. 15

    Python - Server listening from two UDP sockets

  16. 16

    Python Sockets - Sending a packet to a server and waiting for a response

  17. 17

    Python Sockets - Sending a packet to a server and waiting for a response

  18. 18

    Server(Python) - Client(Java) communication using sockets

  19. 19

    Unix Domain Sockets C Server and Python Client

  20. 20

    Programming Python with an EasyPHP server?

  21. 21

    Programming Python with an EasyPHP server?

  22. 22

    Cache a HTTP GET REQUEST in Python Sockets

  23. 23

    How to get the Domain name in Python sockets?

  24. 24

    How to get html code using python sockets

  25. 25

    Python socket server/client programming

  26. 26

    Checking for open ports on a remote server using sockets hangs when the port is closed, C

  27. 27

    redis-server run multiple times binds multiple listening sockets on the same port?

  28. 28

    How to get arduino port with python

  29. 29

    Any Port Issue : Python is hanging at STSConnection().get_session_token In server , But Works fine in my laptop

HotTag

Archive