How read Gmail via POP3 with ActivePerl 5.10 on Windows XP? - perl

I'm using Windows XP SP3 with ActiveState Perl 5.10.0, and I've written this function--taken/edited from CPAN's Net::POP3--in an attempt to read Gmail via POP3:
my $pop = Net::POP3->new('pop.gmail.com',
Timeout => 60,
Port => 995,
Debug => 1) || die "$!";
my $num = $pop->login('xyz#gmail.com', 'password');
if (!defined($num))
{
die "Error: couldn't sign-in to your email account.\n";
}
elsif ($num > 0)
{
warn "There are $num message(s) in your inbox.\n";
my $msgnums = $pop->list;
foreach my $msgnum (keys %$msgnums)
{
my $msg = $pop->get($msgnum);
print #$msg;
}
}
else
{
die "There are no messages in your inbox. (Nothing to do.)\n"
}
$pop->quit;
The code simply times-out with this error message:
Use of uninitialized value in numeric eq (==) at C:/Perl/lib/Net/POP3.pm line 59.
Bad file descriptor at pop3.pl line xxx (i.e., the Net::POP3->new() line)
The debug info from Net::POP3 before the timeout occurred was:
Net::POP3>>> Net::POP3(2.29)
Net::POP3>>> Net::Cmd(2.29)
Net::POP3>>> Exporter(5.62)
Net::POP3>>> IO::Socket::INET(1.31)
Net::POP3>>> IO::Socket(1.30_01)
Net::POP3>>> IO::Handle(1.27)
Net::POP3=GLOB(0x20d253c): Timeout at pop3.pl line xxx
I also tried using Mail::POP3Client; no joy on Windows XP because neither CPAN nor PPM would install it and its dependencies (IO::SOCKET::SSL and etc.).
Any ideas what's wrong with my code and/or how one can read Gmail via POP3 on Windows XP with ActivePerl 5.10.0?
According to Gmail, the standard configuration instructions are:
Incoming Mail (POP3) Server - requires SSL: pop.gmail.com
Use SSL: Yes
Port: 995

You need to use SSL to access GMail. This means you need to install the Perl module IO::Socket::SSL. But this is very simple. ActiveState ships a good cpan client and a huge amount of binary 'PPM' packages. It does require that you upgrade Perl to 5.14 or 5.16 or get some kind of contract they require for supporting older perls.
You can also use Strawberry Perl; it has an equally good cpan client + build tools.

Related

Net::SSH:Perl can't login SSH1

I'm trying to connect me to a switch using SSH1 (the switch is old and does not support ssh2) and after the firsts steps, my program dosen't do nothing and i have to Ctrl+C to stop it
# Perl v5.8.8 built for MSWin32-x86-multi-thread
#!perl
use strict;
use warnings;
use Net::SSH::Perl;
my $host = "10.*.*.*";
my $username = "***";
my $password = "***";
my $cmd = 'show version';
my $ssh = Net::SSH::Perl->new($host, debug => 1);
$ssh->login($username, $password);
my($stdout, $stderr, $exit) = $ssh->cmd($cmd); #the script stops here
print $stdout;
logs :
Connecting to 10.*.*.*, port 22.
Remote version string: SSH-1.5-OpenSSH_2.9p1
Remote protocol version 1.5, remote software version OpenSSH_2.9p1
Net::SSH::Perl Version 1.42, protocol version 1.5.
No compat match: OpenSSH_2.9p1.
Connection established.
Waiting for server public key.
Received server public key (512 bits) and host key (896 bits).
Host '10.*.*.*' is known and matches the host key.
Encryption type: DES3
Sent encrypted session key.
Received encryption confirmation.
Trying password authentication.
Sending command: show version
Entering interactive session.
Terminating on signal SIGINT(2) #Ctrl-C
i can log me in with putty and it works.
I used wiresharck and we can see that the password and maybe the login are not used counter to putty http://image.noelshack.com/fichiers/2016/31/1470038197-troubleshooting2-ssh1.png, packets are too lights.
I don't understand what's going wrong, why the connection failed and logs say nothing about it.
It seems that it's a problem about my 3 HP switch (2524,5304, 5130). I finally tested on a cisco switch and it works perfeclty........
I will search a solution in they key size or something like that
Edit : i'm using python now and its the same problem but i found the solution here http://forums.juniper.net/t5/ScreenOS-Firewalls-NOT-SRX/Python-Paramiko-with-netscreen/m-p/294864

inet_pton is not a valid Socket macro

I am getting below error with perl package 5.10.
"inet_pton is not a valid Socket macro"
if (Socket::inet_pton (AF_INET6,$self->{'ip'}) )
{
$log->print("we hit here and ip=$self->{'ip'}");
$self->{'session'} = Net::SNMP->session(-hostname => $self->{'ip'},
-community => $self->{'community'},
-port => $self->{'port'},
-version => 'snmpv2c');
}
Can you pls let me know the root cause ?
Socket uses an autoloader. That's the message it produces when you try to call a sub that doesn't exist.
$ perl -MSocket -wE'my $x = Socket::some_name()'
some_name is not a valid Socket macro at -e line 1
In other words, the error message is synonymous with
Undefined subroutine &Socket::inet_pton called
You must have a version of Socket that predates the addition of the module's support for inet_pton. Therefore, the fix is simply to upgrade that module.
Your Perl is too old. As far as I can tell, inet_pton support wasn't added until 5.12. Installing a newer version of Socket from CPAN may help, but I wouldn't bet on it. Perl 5.10 came out in 2007, and the IPv6 support back then was much worse than it is today.

IO/Pty error when compiling PERL script

It has been awhile since I have done any PERL programming and I am working on a project where I need to connect to a remote server and get a listing of files. The script is being developed on a Windows 2012 server using ActivePerl.
This is the script that I have put together, from other examples -
#! /usr/bin/env perl
use strict;
use warnings;
use feature qw(say);
use autodie;
use Net::SFTP::Foreign;
# US Server Configuration
use constant {
HOST => "samplehost",
REMOTE_DIR => "sample/remote",
LOCAL_DIR => "sample/local",
PORT => "3235",
USER_NAME => "username",
PASSWORD => "D%password",
DEBUG => "0",
};
my $stfp = Net::SFTP::Foreign->new (
HOST,
timeout => 240,
user => USER_NAME,
password => PASSWORD,
port => PORT,
autodie => 1,
);
#
# List remote directory contents
#
my $remotefiles;
$remotefiles = $stfp->ls(REMOTE_DIR);
#
# Loop through remote files and print each filename
#
foreach ($remotefiles){
my $file = $_;
my $filename = $file->{filename};
if($filename ne "." && $filename ne ".."){
print"the filename is $filename";
}
}
I am receiving an error when I compile it -
C:\development>perl ConvertPDFs.pl
password authentication not available, IO::Pty is not installed or failed to loa
d: Can't locate IO/Pty.pm in #INC (#INC contains: C:/Perl64/site/lib C:/Perl64/l
ib .) at C:/Perl64/site/lib/Net/SFTP/Foreign/Backend/Unix.pm line 256.
at ConvertPDFs.pl line 20.
Not sure what the problem is.
Pseudo-ttys are a unix construct. If a module requires IO::Pty, it won't run on Windows (though maybe on cygwin). On the plus side, the error message makes it sound like Net::SFTP::Foreign only uses IO::Pty for password-based authentication, so you could avoid the problem by switching to key-based authentication.

Undefined subroutine LWP::Protocol::https::Socket::can_read called

I'm trying to script some interaction between a Linux box and an ESXi host, using the VMware Perl library (which appears to call a SOAP service on the ESXi host).
I am getting an error for which I can't find a solution: Undefined subroutine &LWP::Protocol::https::Socket::can_read called at /usr/local/share/perl5/LWP/Protocol/http.pm line 22
I am currently running Net-HTTP-6.03. I did try with Net-HTTP-6.05 but it makes the web-based calls very slow (and subsequent ones also eventually fail, instead with about 1.2MB of XML as the error message) -- which various forums suggest is only resolvable by reverting to 6.03 (via cpan install GAAS/Net-HTTP-6.03.tar.gz).
The crux of my code is as follows:
use VMware::VIRuntime;
my $context = {
options => ParseOptions(), # result of using GetOpts::Long to parse command-line
session => undef
};
$ENV{PERL_NET_HTTPS_SSL_SOCKET_CLASS} = "Net::SSL"; # Suppresses SSL_VERIFY_NONE
if ($context->{options}->{'ignore-ssl-errors'}) {
$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0; # Ignores certificate errors
}
## next line fails
$context->{session} = Vim::login(
service_url => $context->{options}->{url},
username => $context->{options}->{username},
password => $context->{options}->{password}
);
Is there something else I (can|need to) do to get this working?
I've got it. I needed to reinstall Bundle::LWP from an older version, not just Net-HTTP. Without it, I had LWP v6.05 trying to talk to Net-HTTP v6.03.
Once I realised that LWP == libwww-perl (yes, I'm that new), I found the overall package I needed:
cpan install GAAS/libwww-perl-6.03.tar.gz
Reproduced with LWP 6.05 and Net::HTTP 6.01, which is the cocktail that MacPorts installs at the time of this writing. Upgrading Net::HTTP to 6.06 (current) solved it:
sudo cpan Net::HTTP

Perl script works OK in command prompt, but fails on ODBC as a CGI script

Issue: Perl script works fine in command prompt, but fails on ODBC as a CGI script
Settings:
Win XP Pro 64 bit version 2003 SP2
Apache 2.2.17 Win32
Active Perl 5.12.2 (not Perl64)
an ODBC DSN is created for SQL SERVER
Details: from command prompt, Phone.pl runs OK - it gets query results as expected - which means DBI works fine
as a CGI script, Phone.pl prints HTML as expected before ODBC init code. (Apache settings work OK for non-ODBC script.)
here's the msg in error.log of Apache
[Tue Nov 23 13:27:57 2010] [error] [client 127.0.0.1] DBI connect('SQLSVR206','administrator',...) failed: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (SQL-IM002) at C:/CGI/Phone.pl line 32
Any idea why it behaves differently?
#!c:/perl/bin/perl.exe
use CGI qw(:standard);
use strict;
use warnings;
use DBI;
my ($sqlstr, $sql_UNITED, $dbh206);
# 206
# select * from getProvFINON('270762789')#TIN
my #colUNITED = qw/ADR_LN_1_TXT PROV_SYS_ID ZIP_CD FULL_NM SOURCE PROV_TIN BILL_TEL/;
sub Init(){
$dbh206 = DBI->connect ("dbi:ODBC:SQLSVR206",'USER','PASSWORD',{RaiseError=>1})
or die $DBI::errstr;
$sqlstr = qq/ select * from getProvFINON(?) /; #parameters TIN
$sql_UNITED = $dbh206->prepare($sqlstr)
or die "prepare failed: " . $dbh206->errstr();
}
sub test1{
my $tin = shift();
$sql_UNITED->execute($tin) or die $sql_UNITED->errstr;
my $row = $sql_UNITED->fetchrow_hashref;
while(defined ($row)){
foreach(#colUNITED){
print $row->{$_}."~~~";
}
print "<p>";
$row = $sql_UNITED->fetchrow_hashref;
}
}
print header;
print "test text<p>";
Init();
test1('270762789');
print "999999999999<p>";
==========================================================
UPDATE: part of the problem is the 32-bit VS 64-bit ODBC issue
see http://support.microsoft.com/kb/942976
HOWEVER, after I set up ODBC, I still got following error in Apache log
[Wed Nov 24 01:38:48 2010] [error] [client 127.0.0.1] DBI connect('SQLSVR206-32','',...) failed: [Microsoft][ODBC SQL Server Driver][SQL Server]Login failed for user 'MYDOMAIN\GARY$'. (SQL-28000) at C:/CGI/test.pl line 15
I logged in as MYDOMAIN\administrator and started Apache.
ODBC was set up to use "With Windows NT authentication using the network login ID" Where does this "MYDOMAIN\GARY$" come from? Thanks!
==========================================================
FINAL UPDATE: Apache services runs using "Local System account", and that's where the "MYDOMAIN\GARY$" comes from. The thing is GARY is not with the company and his ID has been dropped from SQL Server, but ODBC code in CGI inherited GARY from Apache, resulting in error 28000.
So the problem was a convolution of
1) 32/64 bit ODBC DSN and
2) default account used by Apache
Maybe the ODBC datasource is listed under 'User DSN' and not 'System DSN'. I think that the identity that your web server runs as only has access to System DSN.
In case my post doesn't make sense, I'm editing it in order to add a link to information about the difference between User vs. System DSN's: http://www.truthsolutions.com/sql/odbc/creating_a_new_odbc_dsn.htm
Something is up with Windows 7 ODBC connections that I can't figure out either. I'd set up the ODBC and it would test fine but get a similar error as you show. Even connecting MS SQL Server Mgmt Studio to some SQL servers I have to explicitly put in extra connection settings. Since I only have the issue on some SQL servers (which I don't own) I think it's a server side problem.
On PERL i finally gave up and just created the DSN file with said extra connection settings and pointed to it directly. Note how the server name is there twice.
use DBI;
use SQL::Abstract;
my $CONNECT = "FILEDSN=thefile.dsn";
my $dbh = DBI->connect("dbi:ODBC:$CONNECT", "myidsid", "passwordThatsNotUsed");
with the ODBC file looking something like:
[ODBC]
DRIVER=SQL Server Native Client 10.0
UID=myidsid
Address=servername,3180
Network=DBMSSOCN
APP=Microsoft® Windows® Operating System
Trusted_Connection=Yes
SERVER=servername
PWD=someTextInPlaceOfPasswordAsItsNotUsed