Skip to content

Commit 3814a84

Browse files
author
Xiong Dezhi
committed
first commit
0 parents  commit 3814a84

25 files changed

+1593
-0
lines changed

GetOptdemo.pl

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/perl
2+
use Getopt::Std;
3+
use Data::Dumper;
4+
getopts(":a:p:", \%args);
5+
if (!defined($args{'a'}) or !defined($args{'p'})) {
6+
print "Usage: perl $0 -a <ip> -p <port>\n";
7+
} else {
8+
print Dumper(\%args);
9+
}
10+

Proc.pl

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/perl
2+
3+
use Proc::ProcessTable;
4+
5+
my $tobj = new Proc::ProcessTable;
6+
my $proctable = $tobj->table();
7+
8+
my $proctable = $tobj->table();
9+
foreach my $process (@$proctable) {
10+
print $process->pid . "\t" . getpwuid( $process->uid ) . "\n";
11+
}
12+
13+
my @fields = $tobj->fields();
14+
print "@fields\n";
15+

chap10_2.pl

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/perl
2+
3+
use strict;
4+
require "chap10_1.pm";
5+
6+
my($sec, $min, $hour, $mday, $mon, $year, $wday) = localtime(time);
7+
my $wdaystr = Oogaboogoo::date::day($wday);
8+
my $monthstr = Oogaboogoo::date::mon($mon);
9+
my $year += 1900;
10+
print "Today is $wdaystr, $monthstr $mday, $year\n";
11+
12+

chap8_1.pl

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/perl
2+
3+
use strict;
4+
use IO::File;
5+
use IO::Tee;
6+
use IO::Scalar;
7+
use POSIX qw/strftime/;
8+
local $\ = "\n";
9+
10+
my $date = strftime("%Y-%m-%d", localtime(time));
11+
my @week = qw/Sun Mon Tue Wed Thu Fri Sat/;
12+
my $wday = (localtime time)[6];
13+
print $week[$wday];
14+
15+
my $fh = IO::File->new("./day.txt", O_CREAT|O_WRONLY|O_APPEND) or die($!);
16+
my $string_log = '';
17+
my $string_fh = IO::Scalar->new(\$string_log, O_RDWR) or die($!);
18+
my $tee_fh = IO::Tee->new($fh, $string_fh) or die($!);
19+
20+
my $user_input = get_option();
21+
if ($user_input eq '1') {
22+
print $fh $date,$week[$wday];
23+
} elsif ($user_input eq '2') {
24+
print $string_fh $date,$week[$wday];
25+
} elsif ($user_input eq '3') {
26+
print $tee_fh $date,$week[$wday];
27+
} else {
28+
print "wrong choice!!!";
29+
}
30+
31+
if ($user_input eq '2' or $user_input eq '3') {
32+
print "2 or 3";
33+
print "strlog: $string_log";
34+
print while (<$string_fh>);
35+
}
36+
37+
38+
sub get_option {
39+
print "1. print to file day.txt";
40+
print "2. print to a scalar";
41+
print "3. print to both";
42+
print "pls enter your choice:[123] ";
43+
my $input = <>;
44+
chomp $input;
45+
die("wrong input ") unless $input =~ m/[123]/;
46+
$input =~ s/[^123]//;
47+
return $input;
48+
}

chap8_2.pl

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/perl
2+
3+
use strict;
4+
use IO::File;
5+
#local $\ = "\n";
6+
7+
my $file = shift or die("I need a filename");
8+
my $fh = IO::File->new($file, O_RDONLY) or die($!);
9+
my %fh_hash;
10+
while (<$fh>) {
11+
my $name = (split ":", $_)[0];
12+
my $name = lc $name;
13+
$fh_hash{$name} = IO::File->new($name.".info", O_CREAT|O_WRONLY|O_APPEND) unless exists $fh_hash{$name};
14+
print {$fh_hash{$name}} $_;
15+
}

chap8_3.pl

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/perl
2+
use strict;
3+
use IO::Dir;
4+
local $\ = "\n";
5+
6+
die("I need at least a dirname") unless @ARGV > 0;
7+
foreach (@ARGV) {
8+
if (-d $_) {
9+
my $dir_fh = IO::Dir->new($_) or die($!);
10+
while (my $content = $dir_fh->read()) {
11+
print $content;
12+
}
13+
$dir_fh->close();
14+
} else {
15+
print "Not a dir : $_";
16+
}
17+
}

chap9_1.pl

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/perl
2+
3+
my @output =
4+
#map { $_->[0] }
5+
sort { $b->[1] <=> $a->[1] }
6+
map { [$_, -s $_] }
7+
glob "/bin/*";
8+
9+
print map { sprintf(" %-30s %-10d\n", $_->[0], $_->[1]) } @output;

dezhi.pl

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
use LWP::UserAgent;
2+
use HTTP::Cookies;
3+
4+
sub createua {
5+
my $cookiefile = shift @_;
6+
my $cookie_jar = HTTP::Cookies->new(
7+
file => "$cookiefile",
8+
autosave => 1,
9+
ignore_discard => 1,
10+
);
11+
my $ua = LWP::UserAgent->new();
12+
push @{ $ua->requests_redirectable }, 'POST';
13+
$ua->agent("Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.21 (KHTML, like Gecko) Chrome/25.0.1349.2 Safari/537.21");
14+
$ua->timeout(5);
15+
$ua->cookie_jar($cookie_jar);
16+
return ($ua, $cookie_jar);
17+
}
18+
19+
1

dns.pl

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/perl
2+
use Data::Dumper;
3+
4+
my @servers = qw/8.8.8.8 61.139.2.69 8.8.4.4 202.106.182.153 218.30.108.100 58.63.238.177 60.28.164.133/;
5+
my $hostname = shift @ARGV;
6+
print $hostname, "\n";
7+
my %results;
8+
foreach my $server (@servers) {
9+
$results{$server} = LookupAddr($hostname, $server);
10+
#print "$server => $results{$server}\n";
11+
}
12+
13+
my %inv = reverse %results;
14+
if (scalar keys %inv > 1 ) {
15+
print Data::Dumper->Dump( [ \%results ], ['results'] ), "\n";
16+
#print Dumper(%results);
17+
}
18+
sub LookupAddr {
19+
my($hostname, $server) = @_;
20+
$nslookup = `which nslookup`;
21+
chomp $nslookup;
22+
open my $NSLOOK, '-|', "$nslookup $hostname $server";
23+
my @results;
24+
while (<$NSLOOK>) {
25+
next until (/^Name/);
26+
chomp ($result = <$NSLOOK>);
27+
$result =~ s/Address(es)?:\s*//;
28+
push @results, $result;
29+
}
30+
#print @results, "\n";
31+
return join(',', @results);
32+
}
33+

flight.pl

+206
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
#!/usr/bin/perl
2+
use strict;
3+
use JSON;
4+
use Data::Dumper;
5+
use Encode;
6+
use Getopt::Std;
7+
use Time::HiRes qw(sleep time);
8+
use MIME::Base64;
9+
require "dezhi.pl";
10+
11+
$| = 1;
12+
13+
my %input;
14+
getopts("c:p:", \%input);
15+
unless ($input{'c'} && $input{'p'}) {
16+
print "Usage: $0 -c cookiefile -p passinfofile\n";
17+
exit(1);
18+
}
19+
20+
my ($ua, $cookie_jar) = createua($input{'c'});
21+
my($fltDate, $airTax, $fuelTax, $username, $pass, $flightid, $ticketNum, $pass1name, $id1, $pass2name, $id2) = getPassInfo($input{'p'});
22+
23+
if (-f $input{'c'}) {
24+
$cookie_jar->load($input{'c'});
25+
checkcookies();
26+
}
27+
28+
sub checkcookies {
29+
my $url = "http://www.capitalairlines.com.cn/frontend/users/register/showinfo.action";
30+
my $res = $ua->get($url);
31+
die("code: $res->code(), can't check cookies, get page error\n") unless $res->is_success();
32+
dologin() unless ($res->content() =~ /$username/i);
33+
}
34+
35+
my($userid, $person, $email, $cell);
36+
getUserInfo();
37+
38+
#my ($lostcabin, $routesid) = getflight();
39+
#while ($lostcabin == -1) {
40+
# sleep 0.1;
41+
# ($lostcabin, $routesid) = getflight();
42+
#}
43+
my $ordercontent = "";
44+
do {
45+
$ordercontent = placeorder();
46+
} while ($ordercontent !~ /$id1/);
47+
print "place order ok\n";
48+
49+
sub dologin {
50+
my $captcha = "";
51+
do {
52+
$captcha = getcaptcha();
53+
} while ($captcha =~ /recap/);
54+
print "code is $captcha\n";
55+
56+
my $loginurl = "http://www.capitalairlines.com.cn/login.action";
57+
my $loginrefer = "http://www.capitalairlines.com.cn/login.action";
58+
my %loginpost = ("userName" => "$username",
59+
"password" => "$pass",
60+
"j_captcha_response" => "$captcha");
61+
print Dumper(\%loginpost);
62+
my $dologin = $ua->post($loginurl, \%loginpost);
63+
if ($dologin->is_success()) {
64+
#print $dologin->as_string();
65+
sleep 1;
66+
} else {
67+
print $dologin->as_string();
68+
die($dologin->code()."do login failed");
69+
}
70+
my $logindone = $ua->get("http://www.capitalairlines.com.cn/");
71+
open(my $fhout, ">", "./cap.html") or die($!);
72+
if ($logindone->is_success()) {
73+
$cookie_jar->save();
74+
print $fhout $logindone->content();
75+
}
76+
}
77+
78+
sub getflight {
79+
my($lostcabin, $routesid);
80+
my $flighturl = "http://www.capitalairlines.com.cn/frontend/groupbuying/groupindex/groupindex!doIndexDetail.action?detailId=$flightid";
81+
print "$flighturl\n";
82+
my $res = $ua->get("$flighturl");
83+
if ($res->is_success()) {
84+
#print "res ok\n";
85+
#print $res->content();
86+
my ($flt) = $res->content() =~ /temptitleId"\s*>([^<]*)</;
87+
my ($routesStr) = $res->content() =~ m/var\s*routesStr\s*=\s*"(.*)";\s*$/m;
88+
$routesStr =~ s/'/"/g;
89+
$routesStr =~ s/root/"root"/;
90+
#print "$routesStr\n";
91+
my $jsonobj = decode_json($routesStr);
92+
#print Dumper(@{ $jsonobj->{'root'} }[0]);
93+
print "$flt: Current max date ${ $jsonobj->{'root'} }[-1]->{'fltDate'}, status: ${ $jsonobj->{'root'} }[-1]->{'status'}, price:${ $jsonobj->{'root'} }[-1]->{'price'} ".time()."\n\n";
94+
foreach (@{ $jsonobj->{'root'} }) {
95+
if ($_->{'fltDate'} =~ /$fltDate/) {
96+
#print Dumper($_);
97+
return (-1, -1) unless $_->{'status'} =~ /OPEN_FOR_SALE/;
98+
$lostcabin = $_->{'lostcabin'};
99+
$routesid = $_->{'id'};
100+
my $lastpage = "http://www.capitalairlines.com.cn/frontend/groupbuying/order/grouporder!passengerInfo.action?routesId=$routesid&cabinNum=$lostcabin";
101+
print "$lastpage\n";
102+
return ($lostcabin, $routesid);
103+
}
104+
}
105+
return (-1, -1);
106+
} else {
107+
print $res->code();
108+
}
109+
}
110+
111+
sub getUserInfo {
112+
my $page = "http://www.capitalairlines.com.cn/frontend/groupbuying/order/grouporder!passengerInfo.action?routesId=7015&cabinNum=15";
113+
my $lastres = $ua->get($page);
114+
my $page = $lastres->content();
115+
#($fuelTax) = $page =~ /fuelTax1"\s*type="hidden"\s*value="([\d\.]+)"/;
116+
#($airTax) = $page =~ /airportTax1"\s*type="hidden"\s*value="([\d\.]+)"/;
117+
#($username) = $page =~ /"condition\.userLogin"\s*id="contactName"\s*type="hidden"\s*class="ipt1"\s*value="(\w+)"/;
118+
($userid) = $page =~ /condition\.userId"\s*id="contactId"\s*type="hidden"\s*class="ipt1"\s*value="(\d+)"/;
119+
($person) = $page =~ /condition\.person"\s*id="contactName"\s*type="text"\s*class="ipt1"\s*value="([^"]+)"/;
120+
($email) = $page =~ /contactEmail"\s*type="text"\s*class="ipt1"\s*value="([\w@\.]+)"/;
121+
($cell) = $page =~ /contactMobile"\s*type="text"\s*class="ipt1"\s*readonly="readonly"\s*value="(\d+)"/;
122+
print "$fuelTax, $airTax, $username, $userid, $person, $email, $cell\n";
123+
}
124+
125+
126+
sub getPassInfo {
127+
my $filename = shift @_ or die("you must supply a filename\n");
128+
open(my $fh, "<", $filename);
129+
while (<$fh>) {
130+
next if /#/;
131+
my($fltDate, $airTax, $fuelTax, $username, $pass, $flightid, $ticketNum, $pass1name, $id1, $pass2name, $id2) = split(" ", $_);
132+
$username = uc($username);
133+
close($fh);
134+
print "$fltDate, $airTax, $fuelTax, $username, $pass, $flightid, $ticketNum, $pass1name, $id1, $pass2name, $id2\n";
135+
return ($fltDate, $airTax, $fuelTax, $username, $pass, $flightid, $ticketNum, $pass1name, $id1, $pass2name, $id2);
136+
}
137+
}
138+
139+
sub placeorder {
140+
my %postform = ("routesId" => '5921',
141+
"airportTax" => $airTax,
142+
"fuelTax" => $fuelTax,
143+
"pass1box" => "unchecked",
144+
"pass2box" => "unchecked",
145+
"ticketNum" => $ticketNum,
146+
"pass1.name" => $pass1name,
147+
"pass1.certificateType" => "NI",
148+
"pass1.certificateNo" => $id1,
149+
"pass2.name" => $pass2name,
150+
"pass2.certificateType" => "NI",
151+
"pass2.certificateNo" => $id2,
152+
"condition.userId" => $userid,
153+
"condition.userLogin" => $username,
154+
"condition.person" => $person,
155+
"condition.userEmail" => $email,
156+
"condition.userMobileNo" => $cell,
157+
"condition.phone" => "",
158+
"confirmBox" => "checkbox");
159+
print Dumper(\%postform);
160+
my $posturl = "http://www.capitalairlines.com.cn/frontend/groupbuying/order/grouporder!submitOrder.action";
161+
my $res = $ua->post($posturl, \%postform);
162+
if ($res->is_success()) {
163+
return $res->content();
164+
}
165+
}
166+
167+
sub testcookie {
168+
my $testurl = "http://123.125.104.101/dezhi/cookie.php";
169+
$ua->get($testurl);
170+
my $res2 = $ua->get($testurl);
171+
print $res2->as_string();
172+
exit();
173+
}
174+
175+
sub getcaptcha {
176+
#open(my $fh, ">", "/var/www/html/dezhi/cap.jpg") or die($!);
177+
my $loginform = "http://www.capitalairlines.com.cn/login.action";
178+
my $rand = rand 1;
179+
my $res = $ua->get($loginform);
180+
if ($res->is_success()) {
181+
my $jpgres = $ua->get("http://www.capitalairlines.com.cn/jcaptcha?.tmp=$rand");
182+
if ($jpgres->is_success()) {
183+
#print $fh $jpgres->content();
184+
my $img_base64 = encode_base64($jpgres->content());
185+
#my %form = ("img" => $jpgres->content());
186+
my %form = ("img" => $img_base64);
187+
$ua->post("http://123.125.104.101/dezhi/img.php?filename=${rand}.jpg", \%form);
188+
print "http://123.125.104.101/dezhi/img/${rand}.jpg\n";
189+
print "enter \"recap\" to get captcha again or enter the captcha code to continue login\n";
190+
#close $fh;
191+
} else {
192+
die("can't get captcha code\n");
193+
}
194+
} else {
195+
die("can't get login form\n");
196+
print $res->as_string();
197+
}
198+
chomp (my $captcha = <STDIN>);
199+
return $captcha;
200+
}
201+
202+
sub testJSON {
203+
my $routesStr = '{"root":[{"id":"5140","price":"100.00","oprice":"2200.00","discount":"0.45","fltNum":"JD5196","fltDate":"2012-12-21","fltDepTime":"20:35","fltArrTime":"0:35","minPersons":"1","tktNum":"3","endPersons":"3","saleStartDate":"2012-12-07 00:00:00.0","status":"SALE_FINISHED","lostcabin":"0","saleEndDate":"2012-12-14 23:59:59.0"},{"id":"5144","price":"100.00","oprice":"2200.00","discount":"0.45","fltNum":"JD5196","fltDate":"2012-12-22","fltDepTime":"20:35","fltArrTime":"0:35","minPersons":"1","tktNum":"2","endPersons":"2","saleStartDate":"2012-12-08 00:00:00.0","status":"SALE_FINISHED","lostcabin":"0","saleEndDate":"2012-12-15 23:59:59.0"},{"id":"5147","price":"100.00","oprice":"2200.00","discount":"0.45","fltNum":"JD5196","fltDate":"2012-12-23","fltDepTime":"20:35","fltArrTime":"0:35","minPersons":"1","tktNum":"2","endPersons":"2","saleStartDate":"2012-12-09 00:00:00.0","status":"SALE_FINISHED","lostcabin":"0","saleEndDate":"2012-12-16 23:59:59.0"},{"id":"5861","price":"100.00","oprice":"2200.00","discount":"0.45","fltNum":"JD5196","fltDate":"2012-12-24","fltDepTime":"20:35","fltArrTime":"0:35","minPersons":"1","tktNum":"-1","endPersons":"-1","saleStartDate":"2012-12-10 00:00:00.0","status":"SALE_FINISHED","lostcabin":"0","saleEndDate":"2012-12-17 23:59:59.0"},{"id":"5868","price":"100.00","oprice":"2200.00","discount":"0.45","fltNum":"JD5196","fltDate":"2012-12-25","fltDepTime":"20:35","fltArrTime":"0:35","minPersons":"1","tktNum":"2","endPersons":"2","saleStartDate":"2012-12-11 00:00:00.0","status":"SALE_FINISHED","lostcabin":"0","saleEndDate":"2012-12-18 23:59:59.0"},{"id":"5875","price":"100.00","oprice":"2200.00","discount":"0.45","fltNum":"JD5196","fltDate":"2012-12-26","fltDepTime":"20:35","fltArrTime":"0:35","minPersons":"1","tktNum":"1","endPersons":"1","saleStartDate":"2012-12-12 00:00:00.0","status":"SALE_FINISHED","lostcabin":"0","saleEndDate":"2012-12-19 23:59:59.0"},{"id":"5880","price":"100.00","oprice":"2200.00","discount":"0.45","fltNum":"JD5196","fltDate":"2012-12-27","fltDepTime":"20:35","fltArrTime":"0:35","minPersons":"1","tktNum":"2","endPersons":"2","saleStartDate":"2012-12-13 00:00:00.0","status":"SALE_FINISHED","lostcabin":"0","saleEndDate":"2012-12-20 23:59:59.0"},{"id":"5895","price":"100.00","oprice":"2200.00","discount":"0.45","fltNum":"JD5196","fltDate":"2012-12-28","fltDepTime":"20:35","fltArrTime":"0:35","minPersons":"1","tktNum":"3","endPersons":"3","saleStartDate":"2012-12-12 00:00:00.0","status":"SALE_FINISHED","lostcabin":"0","saleEndDate":"2012-12-21 00:00:00.0"}]}';
204+
my $jsonobj = decode_json($routesStr);
205+
print Dumper($jsonobj);
206+
}

0 commit comments

Comments
 (0)