Skip to content

Commit 3e4d4a2

Browse files
committed
Allow non-numeric ports with remote()
1 parent b3b6d52 commit 3e4d4a2

File tree

3 files changed

+6
-8
lines changed

3 files changed

+6
-8
lines changed

pwnlib/tubes/listen.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,13 @@ def __init__(self, port=0, bindaddr='::',
7878
fam='any', typ='tcp', *args, **kwargs):
7979
super(listen, self).__init__(*args, **kwargs)
8080

81-
port = int(port)
82-
8381
fam = self._get_family(fam)
8482
typ = self._get_type(typ)
8583

8684
if fam == socket.AF_INET and bindaddr == '::':
8785
bindaddr = '0.0.0.0'
8886

89-
h = self.waitfor('Trying to bind to %s on port %d' % (bindaddr, port))
87+
h = self.waitfor('Trying to bind to %s on port %s' % (bindaddr, port))
9088

9189
for res in socket.getaddrinfo(bindaddr, port, fam, typ, 0, socket.AI_PASSIVE):
9290
self.family, self.type, self.proto, self.canonname, self.sockaddr = res
@@ -109,7 +107,7 @@ def __init__(self, port=0, bindaddr='::',
109107
break
110108
else:
111109
h.failure()
112-
self.error("Could not bind to %s on port %d" % (bindaddr, port))
110+
self.error("Could not bind to %s on port %s" % (bindaddr, port))
113111

114112
h.success()
115113

pwnlib/tubes/remote.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def __init__(self, host, port,
6161
*args, **kwargs):
6262
super(remote, self).__init__(*args, **kwargs)
6363

64-
self.rport = int(port)
64+
self.rport = port
6565
self.rhost = host
6666

6767
if sock:
@@ -99,7 +99,7 @@ def _connect(self, fam, typ):
9999
sock = None
100100
timeout = self.timeout
101101

102-
with self.waitfor('Opening connection to %s on port %d' % (self.rhost, self.rport)) as h:
102+
with self.waitfor('Opening connection to %s on port %s' % (self.rhost, self.rport)) as h:
103103
for res in socket.getaddrinfo(self.rhost, self.rport, fam, typ, 0, socket.AI_PASSIVE):
104104
self.family, self.type, self.proto, _canonname, sockaddr = res
105105

@@ -123,7 +123,7 @@ def _connect(self, fam, typ):
123123
raise
124124
except socket.error:
125125
pass
126-
self.error("Could not connect to %s on port %d", self.rhost, self.rport)
126+
self.error("Could not connect to %s on port %s", self.rhost, self.rport)
127127

128128
@classmethod
129129
def fromsocket(cls, socket):

pwnlib/tubes/sock.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def close(self):
175175
self._close_msg()
176176

177177
def _close_msg(self):
178-
self.info('Closed connection to %s port %d', self.rhost, self.rport)
178+
self.info('Closed connection to %s port %s', self.rhost, self.rport)
179179

180180
def fileno(self):
181181
if not self.sock:

0 commit comments

Comments
 (0)