Net::Connection - Represents a network connection as a object.
Version 0.0.0
use Net::Connection; #create a hash ref with the desired values my $args={ 'foreign_host' => '1.2.3.4', 'local_host' => '4.3.2.1', 'foreign_port' => '22', 'local_port' => '11132', 'sendq' => '1', 'recvq' => '0', 'pid' => '34342', 'uid' => '1000', 'state' => 'ESTABLISHED', 'proto' => 'tcp4' }; # create the new object using the hash ref my $conn=Net::Connection->new( $args ); # the same thing, but this time resolve the UID to a username $args->{'uid_resolve'}='1'; $conn=Net::Connection->new( $args ); # now with PTR lookup $args->{'ptrs'}='1'; $conn=Net::Connection->new( $args ); # prints a bit of the connection information... print "L Host:".$conn->local_host."\n". "L Port:".$conn->local_host."\n". "F Host:".$conn->foreign_host."\n". "F Port:".$conn->foreign_host."\n";
This initiates a new connection object.
One argument is taken is taken and it is a hash reference. The minimum number of arguements is as below.
local_host local_port foreign_host foreign_port proto state
The local host of the connection.
This can either be a IP or hostname. Max utility is achieved via a IP though as that allows PTR lookup to be done.
If appears to be a hostname, it is copied to local_ptr and even if asked to resolve PTRs it won't attempt to.
This is the foreign port of the connection.
For best utility, using numeric here is best.
If ports is true it will attempt to resolve it, including reverse resolving if it is a port name instead.
If ports is false or not set and this value is non-numeric, it will be copied to foreign_port_name.
This is the name of foreign port, if one exists in the service records.
This is the PTR address for foreign_host.
If ptrs is not true and foreign_host appears to be a hostname, then it is set to the same as foreign_host.
This is the local port of the connection.
If ports is false or not set and this value is non-numeric, it will be copied to local_port_name.
This is the name of local port, if one exists in the service records.
This is the PTR address for local_host.
If ptrs is not true and local_host appears to be a hostname, then it is set to the same as local_host.
This is the pid for a connection.
If defined, it needs to be numeric.
If true, it will attempt to resolve the port names.
This is the protocol type.
This needs to be defined, but unfortunately no real checking is done as of currently as various OSes uses varrying capitalizations and slightly different forms of TCP, TCP4, tcp4, tcpv4, and the like.
If is true, then attempt to look up the PTRs for the hosts.
This is the recieve queue size.
If set, it must be numeric.
This is the send queue size.
This is the current state of the connection.
This needs to be defined, but unfortunately no real checking is done as of currently as there are minor naming differences between OSes as well as some including states that are not found in others.
The UID is the of the user the has the connection open.
This must be numeric.
If uid_resolve is set to true then the UID will be resolved and stored in username.
If this is not defined, uid_resolve is true, and username is defined then it will attempt to resolve the UID from the username.
If set to true and uid is given, then a attempt will be made to resolve the UID to a username.
This is the username for a connection.
If uid_resolve is true and uid is defined, then this will attempt to be automatically contemplated.
Returns the foreign host.
my $f_host=$conn->foreign_host;
This returns the foreign port.
my $f_port=$conn->foreign_port;
This returns the foreign port name.
This may potentially return undef if one is not set/unknown.
This returns the PTR for the foreign host.
If one was not supplied or if it could not be found if resolving was enabled then undef will be returned.
my $f_ptr=$conn-<foreign_ptr;
Returns the local host.
my $l_host=$conn->local_host;
This returns the local port.
my $l_port=$conn->local_port;
This returns the local port name.
This returns the PTR for the local host.
my $l_ptr=$conn->local_ptr;
Returns the protocol in use by the connection.
Please note this value with vary slightly between OSes.
my $proto=$conn->proto;
Returns the size of the recieve queue the connection.
This may return undef.
my $recvq=$conn->recvq;
Returns the size of the send queue the connection.
my $sendq=$conn->sendq;
Returns the state the connection is currently in.
my $state=$conn->state;
Returns the UID that has the connection.
This may not be if it was not set. Please see new for more information.
my $uid=$conn->uid;
Returns the username that has the connection.
my $username=$conn->username;
Zane C. Bowers-Hadley, <vvelox at vvelox.net>
<vvelox at vvelox.net>
Please report any bugs or feature requests to bug-net-connection at rt.cpan.org, or through the web interface at https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-Connection. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-net-connection at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc Net::Connection
You can also look for information at:
RT: CPAN's request tracker (report bugs here)
https://rt.cpan.org/NoAuth/Bugs.html?Dist=Net-Connection
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Net-Connection
CPAN Ratings
https://cpanratings.perl.org/d/Net-Connection
Search CPAN
https://metacpan.org/release/Net-Connection
Repository
http://gitea.eesdp.org/vvelox/Net-Connection
This software is Copyright (c) 2019 by Zane C. Bowers-Hadley.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)
To install Net::Connection, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Net::Connection
CPAN shell
perl -MCPAN -e shell install Net::Connection
For more information on module installation, please visit the detailed CPAN module installation guide.