TCP server ignores my SYN request from NET::RawIP - perl

I use small perl script:
#!/usr/bin/perl -w
use Net::RawIP;
$a = new Net::RawIP({
ip =>
{
daddr => '192.168.0.100'
},
tcp =>
{
source => 41218,
dest => 80,
syn => 1
}
});
$a->send;
and server doesn't send any response.
More detailed information from wireshark:
screen
I expected to get response from server. So, what's wrong ?

Validate the checksum, packets are dropped if the checksum is invalid

Related

Cannot sysread (): EOF Error while connecting to Tibco JMS Topic using Net:: STOMP:: Client

I am using the Net::STOMP::Client module to connect to a Tibco JMS Topic Server which is not hosted by me.
I am trying the SSL approach for which, I have a certificate.p12 file from which I generated cert.pem & key.pem and passed it to Net::Stomp::Client. I am using the Authen::Credential::x509 module for cert based authentication.
Now I am getting the following Error when I am trying to run the perl script:
DEBUG: .../IO/Socket/SSL.pm:605: socket not yet connected
DEBUG: .../IO/Socket/SSL.pm:607: socket connected
DEBUG: .../IO/Socket/SSL.pm:629: ssl handshake not started
DEBUG: .../IO/Socket/SSL.pm:662: using SNI with hostname mmx-nprd3-07.cisco.com
DEBUG: .../IO/Socket/SSL.pm:697: request OCSP stapling
DEBUG: .../IO/Socket/SSL.pm:787: ssl handshake done
# 2016/02/10-07:18:33 JmsClient.pl[6618]: connect to stomp+ssl://mmx-ntard-07.sammy.com:7222 ok: 160.**.1**.**2
Stomp Client Object Created
Connected to broker mmx-ntard-07.sammy.com (IP 1**.*8.**.**2), port 7222
# 2016/02/10-07:18:33 JmsClient.pl[6618]: Net::STOMP::Client=HASH(0x194df00)->connect()
# 2016/02/10-07:18:33 JmsClient.pl[6618]: encoding CONNECT frame
# 2016/02/10-07:18:33 JmsClient.pl[6618]: H accept-version:1.0,1.1,1.2
# 2016/02/10-07:18:33 JmsClient.pl[6618]: H host:mmx-ntard-07.sammy.com
# 2016/02/10-07:18:33 JmsClient.pl[6618]: sent 65 bytes
# 2016/02/10-07:18:33 JmsClient.pl[6618]: received 12 bytes
# 2016/02/10-07:18:34 JmsClient.pl[6618]: received 0 bytes
cannot sysread(): EOF
Below is the perl script :-
use Net::STOMP::Client;
use No::Worries::Log qw(*);
use IO::Socket::SSL;
use FindBin qw($Bin);
use Authen::Credential::x509;
$IO::Socket::SSL::DEBUG = 2;
log_filter("debug");
my $auth = Authen::Credential::x509->new(
# client certificate to present
cert => "$Bin/JmsCertificate/aix_jms_public_Cert.pem",
# # client private key
key => "$Bin/JmsCertificate/aix_jms_private_Key.pem",
pass => 'password'
);
my $stomp = Net::STOMP::Client->new(
uri => "stomp+ssl://mmx-ntard-07.sammy.com:7222",
auth => $auth,
debug => 'all',
);
print "\nStomp Client Object Created";
my $peer = $stomp->peer();
printf("\nConnected to broker %s (IP %s), port %d\n", $peer->host(), $peer->addr(), $peer->port());
$stomp->connect();
print "\nConnected\n";
my $sid = $stomp->uuid();
$stomp->subscribe(
destination => "/queue/test",
# we use the generated subscription id
id => $sid,
# we want a receipt on our SUBSCRIBE frame
receipt => $stomp->uuid(),
);
my $count = 0;
my $frame;
while ($count < 10) {
$frame = $stomp->wait_for_frames(timeout => 1);
if ($frame) {
if ($frame->command() eq "MESSAGE") {
$count++;
printf("received message %d with id %s\n",
$count, $frame->header("message-id"));
} else {
# this will catch the RECEIPT frame
printf("%s frame received\n", $frame->command());
}
} else {
print("waiting for messages...\n");
}
}
$stomp->unsubscribe(id => $sid);
$stomp->disconnect();
I am not able to figure out what is going on here. I saw couple of other posts too but they were for ActiveMQ. I'm not sure if that would make a difference.

connect to localhost failed (Connection refused) no (more) retries

I want to send an email using perl ,but when i execute the command as follows:
#./sendmail.sh "par1" "par2" "par3"
i got the error msg "connect to localhost failed (Connection refused) no (more) retries"
sendmail.sh:
/usr/bin/perl /code/sendmail.pl "$1" "$2" "$3";
sendmail.pl:
#!/usr/bin/perl -w
use Mail::Sendmail;
my $event1 = shift(#ARGV);
my $event2 = shift(#ARGV);
my $time = shift(#ARGV);
#my $info = shift(#ARGV);
my $datetime = `/bin/date "+20%y-%m-%d %H:%M:%S"`;
chomp $datetime;
$msg = "This is Monitor System speak:\n
The system discovers the events at $datetime.
Something may be abnormal, please check it. The detail is below:\n";
$msg = $msg."$event1 and $event2 at $time\n";
$msg = $msg."\n";
$msg = $msg."Any problem, check it from http://map_test.php\n\n\n";
$mail_subject = "Abnormal";
sendmail(
From => 'localhost',
To => 'test#mail.com',
Subject => $mail_subject,
Message => $msg,
);
Any help appreciated.
smtp stands for simple mail transfer protocol.
When you need to send an email your mail client needs to talk to an smtp server which will accept the message. Normally your internet service provider will provide an smtp host. If you look at your mail client it will need to have an smtp server configured to be able to send mail.
Ok so when you install the Mail::Sendmail module, it doesn't know what your smtp server will be. It is up to you to tell it. It provides a default of localhost which would often be true if your server is running a sendmail daemon.
The configuration of Mail::Sendmail is stored in a variable called
%Mail::Sendmail::mailcfg
You can change the value of the sendmail server using this snippet of code:
unshift #{$Mail::Sendmail::mailcfg{'smtp'}} , 'my.smtp.server';
You need to add this line of code to your script to set the smtp server.
It adds this server to an array which also includes localhost.
So if neither of the hosts work it will still print an error message about localhost which is slightly confusing.
If you use Data::Dumper to print the contents of the mailcfg variable it will look something like this:
#!/usr/bin/perl
use Mail::Sendmail;
use Data::Dumper;
unshift #{$Mail::Sendmail::mailcfg{'smtp'}} , 'my.smtp.server';
print Dumper(\%Mail::Sendmail::mailcfg);
Should return:
$VAR1 = {
'retries' => 1,
'smtp' => [
'my.smtp.server',
'localhost'
],
'delay' => 1,
'port' => 25,
'from' => '',
'debug' => 0,
'tz' => '',
'mime' => 1
};

Sending requests to perl socket

I am trying to send and receive requests to the same socket in the following fashion.
open socket
send LOGINPDU,
recv response from server and if ok send TRANSPDU
recv response from server
send LOGOUTPDU.
Sample of what am trying to do below:
#1
my $sock = IO::Socket::INET->new( Proto=> "tcp", PeerAddr => "$IP",
PeerPort => "$port") ||
die "Could not connect to host => $IP:$port \n";
#2
print $sock $LOGINPDU."\n";
#3
while($ans=<$sock>) {
$ans1.=$ans;
}
$sock->flush();
if($ans1) {
print $sock $transPDU."\n";
#4
while($tns=<$sock>) {
$tns.=$tns;
}
}
#5
$sock->close();
The problem is that I am only receiving response for the first request.
I would guess that the problem is that your script stays in the first while loop, which waits for the response lines after LOGINPDU is sent to the server (step 2 -> 3)). This is because readline (< >) is blocking and the server did not send an EOF, which is (with your) code the only option to get out of the loop, but as a side-effect it would also close the connection.
So, if the server's answer is (only) one line you can try something like this:
$ans1=<$sock>;
$sock->flush();
if($ans1) {
...
}
Hope that helped a bit.

Can't call method "headers" on an undefined value at C:/Perl/site/lib/Net/Stomp. pm line 122

I am trying to send EMS message from Perl to queue running in the EMS server. I'm using STOMP module to connect to EMS queue for sending message. Here is my code -
JMSQUEUE.pl:
use Net::Stomp;
use Net::Stomp::Frame;
my $stomp = Net::Stomp->new( { hostname => 'localhost', port => '7222' } );
$stomp->connect( { login => 'admin', passcode => '' } );
$stomp->send( { destination => '/queue/pradeepexp', body => 'test message' } );
$stomp->disconnect;
and in my module - STOMP.PM:
sub connect {
my ( $self, $conf ) = #_;
my $frame =
Net::Stomp::Frame->new( { command => 'CONNECT', headers => $conf } );
$self->send_frame($frame);
$frame = $self->receive_frame;
# Setting initial values for session id, as given from
# the stomp server
$self->session_id( $frame->headers->{session} );
$self->_connect_headers($conf);
return $frame;
}
Any settings I need to do before calling connect?
I had the same problem with sending messages from Perl to ApacheMQ.
(Perl + Net-Stomp-0.45 + apache-activemq-5.8)
It was just a little mistake.
It is important to set the correct transportConnectors in this file harddisk\apache-activemq-5.8\conf\activemq.xml.
<transportConnectors>
<transportConnector name="stomp" uri="stomp://localhost:61616"/>
</transportConnectors>
After that it works fine :D
For more information: http://activemq.apache.org/stomp.html
Maybe there are similar files in EMS.
This happens because the Stomp library receives an invalid (or no) response from the message broker.
Try to telnet to the message broker and see if it speaks Stomp at all.

How to send an IP broadcast message using Perl

I've tried both Net::RawIP and Net::Write::Layer3. It works fine if i supply a specific ip address in the network. while i'm getting either
sendto() at /usr/lib/perl5/Net/RawIP.pm line 630. shell returned 13
or
Net::Write::Layer::send: Permission denied
if i change the destination address to 66.66.66.255
any ideas?
the code i'm using is here
use Net::Write::Layer qw(:constants);
use Net::Write::Layer3;
use NetAddr::IP;
use Net::RawIP;
$message = "Foo";
# using Net::RawIP
$n = Net::RawIP->new({
ip => {
tos => 0xC0,
daddr => '66.66.66.2',
protocol => 2,
},
generic => {
data => $message
}
});
$n->send;
# using Net::Write::Layer3
my $desc = Net::Write::Layer3->new(
dst => '66.66.66.2',
protocol => '2',
family => NW_AF_INET,
);
$desc->open;
$desc->send($message);
$desc->close;
Error 13 is usually EACCES - i.e. you do not have sufficient permission to send to a broadcast socket.