Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open port & get remote IP

Status
Not open for further replies.

Crundy

Programmer
Jul 20, 2001
305
GB
Hi All,
I want to open a port on my server, e.g. port 7070 and just log the remote client's IP address and close the connection when someone telnets to port 7070. Can anyone give me a hand?

C:\DOS:>
C:\DOS:>RUN
RUN DOS RUN!!
 
I found this:
Code:
#!/usr/bin/perl

use IO::Socket;

$sock = new IO::Socket::INET(
LocalPort => 2501,
Proto => 'tcp',
Listen => 10,
Reuse => 1,
Type => SOCK_STREAM );
die $@ unless $sock;

print "Listening for incoming connections...\n";
while ( $new_sock = $sock->accept() ) {
$clnt = $sock->sockhost();
print "New connection from $clnt...\n";
$new_sock->close;
}

but it just gets 0.0.0.0 as the IP address. I tried chaging the line:
$clnt = $sock->sockhost();
to:
$clnt = $new_sock->sockhost();
but as expected it gives the server IP address. Any ideas?

C:\DOS:>
C:\DOS:>RUN
RUN DOS RUN!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top