Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
Welcome to the Monastery
 
PerlMonks  

Re: How to select NTLM authentication with LWP

by Khen1950fx (Canon)
on Oct 11, 2011 at 03:00 UTC ( #930731=note: print w/ replies, xml ) Need Help??


in reply to How to select NTLM authentication with LWP

You forgot ntlmv2(1). Try this:

#!/usr/bin/perl use LWP::UserAgent; use HTTP::Request::Common; use LWP::Debug qw(+); use Authen::NTLM; use strict; use warnings; ntlmv2(1); my $url = "http://10.1.1.1"; my $ua = new LWP::UserAgent(keep_alive => 1); $ua->credentials('10.1.1.1:80', '', 'myDomain\\user', 'password'); my $req = GET $url; print "--Peforming request now...---------\n"; my $res = $ua->request($req); if ($res->is_success) { print $res->content; } else { print "Error: " . $res->status_line . "\n"; print $res->headers()->as_string(), "\n"; } exit 0;


Comment on Re: How to select NTLM authentication with LWP
Select or Download Code
Re^2: How to select NTLM authentication with LWP
by tiedwu (Initiate) on Oct 11, 2011 at 03:42 UTC
    elvis@elvis-laptop:~/tmp/person$ ./d2.pl Undefined subroutine &main::ntlmv2 called at ./d2.pl line 10.
    It is weird. The module Authen::NTLM was installed at:
    elvis@elvis-laptop:~/tmp/person$ ls -al /usr/local/share/perl/5.10.1/A +uthen/NTLM.pm -r--r--r-- 1 root root 7116 2011-10-10 15:48 /usr/local/share/perl/5.1 +0.1/Authen/NTLM.pm
      I've updated the latest version NTLM-1.09 which provides ntlmv2(), it still doesn't work and it will not have a redirect to 10.1.1.2. I am confusing which one is workable, NTLM-1.09 made by Nick Bebout or NTLM-1.02 made by Mark J Bush? The output:
      elvis@elvis-laptop:~/tmp/person$ ./d2.pl --Peforming request now...--------- --Done with request ...--------- Error: 401 Unauthorized Date: Tue, 11 Oct 2011 03:43:53 GMT Server: Microsoft-IIS/6.0 WWW-Authenticate: Negotiate WWW-Authenticate: NTLM Content-Length: 1327 Content-Type: text/html Client-Date: Tue, 11 Oct 2011 03:47:44 GMT Client-Peer: 10.1.1.1:80 Client-Response-Num: 1 Client-Warning: Unsupported authentication scheme 'negotiate' Title: ��δ����Ȩ&#6 +5533;鿴��ҳ X-Powered-By: ASP.NET
        For clarifying if it is related to the patch of /usr/local/share/perl/5.10.1/LWP/Authen/Ntlm.pm, I covered it back and update the new output:
        --Peforming request now...--------- --Done with request ...--------- Error: 401 Unauthorized Date: Tue, 11 Oct 2011 04:32:33 GMT Server: Microsoft-IIS/6.0 WWW-Authenticate: Negotiate WWW-Authenticate: NTLM Content-Length: 1251 Content-Type: text/html Client-Date: Tue, 11 Oct 2011 04:36:23 GMT Client-Peer: 10.1.1.1:80 Client-Response-Num: 7 Client-Warning: Credentials for 'domain\user' failed before Title: ��δ����Ȩ&#6 +5533;鿴��ҳ X-Powered-By: ASP.NET
        The perl script is following:
        #!/usr/bin/perl use LWP::UserAgent; use HTTP::Request::Common; use LWP::Debug qw(+); use Authen::NTLM; use strict; use warnings; ntlmv2(1); my $url = "http://10.1.1.1"; my $ua = new LWP::UserAgent(keep_alive => 1); $ua->credentials('10.1.1.1:80', '', 'domain\user', 'password'); my $req = HTTP::Request->new(GET => $url); print "--Peforming request now...---------\n"; my $res = $ua->request($req); print "--Done with request ...---------\n"; # check the outcome if ($res->is_success) { print $res->content; } else { print "Error: " . $res->status_line . "\n"; print $res->headers()->as_string(), "\n"; } exit 0;

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://930731]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (9)
As of 2014-04-23 11:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (541 votes), past polls