Created
August 14, 2013 07:51
-
-
Save ozuma/6228827 to your computer and use it in GitHub Desktop.
Send a raw TCP or UDP packet. (Perl Module)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # use lib qw(./lib); | |
| # use Packet::Simple; | |
| # my $obj = Packet::Simple->new("192.168.1.2", 50001); | |
| # $obj->send_tcp(); | |
| package Packet::Simple; | |
| use strict; | |
| use warnings; | |
| our $VERISON = '0.01'; | |
| use Socket; | |
| sub new { | |
| my $self = shift; | |
| my ($iaddr, $port) = @_; | |
| return bless { | |
| iaddr => $iaddr, | |
| port => $port, | |
| }, $self; | |
| } | |
| sub send_udp { | |
| my $self = shift; | |
| my $proto = getprotobyname('udp'); | |
| socket(Socket_Handle, PF_INET, SOCK_DGRAM, $proto); | |
| send(Socket_Handle, 0, 0, sockaddr_in($self->{port}, inet_aton($self->{iaddr}))); | |
| } | |
| sub send_tcp { | |
| my $self = shift; | |
| my $proto = getprotobyname('tcp'); | |
| socket(Socket_Handle, PF_INET, SOCK_STREAM, $proto); | |
| connect(Socket_Handle, sockaddr_in($self->{port}, inet_aton($self->{iaddr}))); | |
| } | |
| 1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment