2008年4月24日 星期四
把十六進位轉十進位
為什麼呢?
因為在PERL的世界裡,不用宣告這個變數是什麼特別格式
一時是整數,有時是字串…
但你要知道如果變數內的2B值如何變成十進位
也就是如果在螢幕上看到的是 A--->ASC II是65(這是十進位表示)---->或是十六進位表示是0x41
這次我是要把AAA當成十六進位的0x00414141轉為十進位的4276545
或許有人會問為什麼要這樣作,因為我目前遇到的問題是封包問題,因封包Packet分析的器Wireshark上某一欄位看到的是1B,我想轉成十進位來看裡面的東西
好比是IP位置,PORT號,轉成十進位比較好看
目的是把ASC II旳值轉成十進位看
#!/usr/bin/perl
use strict;
my $tt;
my $go1=chr(65); #大寫A的十進位為65
my $go2=chr(0x41); #大寫A的十六進位為41
my $go3=chr(0x41);
my $text="$go1$go2$go3"; #合起來當作是十六進位0AAA轉十進位來看
print "$text\n";
my $tot=0;
my $ligh=length($text);
for(my $i=0;$i < $ligh;$i++){
my $SC=substr($text,$i,1);
if(ord($SC)!=0 ){
$tt=int(ord($SC)/16)*(16**(($ligh*2)-($i*2)-1))+int(ord($SC)%16)*(16**(($ligh*2)-($i*2)-2));
#print " $i\t".ord($SC)."\t$SC\t";
print $tt,'+';
}
$tot=$tot+$tt;
}
print ' 轉成10進位後',"\t$tot\n";
2008年4月23日 星期三
最近買了一本好書
在於支持作者,我還是跑去買了一本
裡面除了解說IO::Socket以外,還說了物件的關係,<>角符號的使用、open()、sysopen()、read()、sysread()、以二進位方式開始檔案的binmode()……
還有很多網路protocol的使用方法
smtp,pop,ftp,imap,nntp,web,telnet……UDP程式設計、Broadcasting、Multicasting
還有用perl寫多執行緒應用程式……
很多很多,這本是一本很好的進階書
原文介紹:
Network Programming with Perl is a comprehensive, example-rich guide to creating network-based applications using the Perl programming language. Among its many capabilities, modern Perl provides a straightforward and powerful interface to TCP/IP, and this book shows you how to leverage these capabilities to create robust, maintainable, and efficient custom client/server applications.
The book quickly moves beyond the basics to focus on high-level, application programming concepts, tools, and techniques. Readers will find a review of basic networking concepts and Perl fundamentals, including Perl's I/O functions, process model, and object-oriented extensions. In addition, the book examines a collection of the best third-party modules in the Comprehensive Perl Archive Network, including existing network protocols for e-mail, news, and the Web.
The core of the book focuses on methods and alternatives for designing TCP-based client/server systems, and more advanced techniques for specialized applications. Some of the specific topics covered are: The Berkeley Sockets API; The TCP protocol and the IO::Socket API; FTP file-sharing service; The Net::Telnet module for adapting clients to interactive network services; SMTP, including how to create and send e-mails with multimedia attachments; HTTP and the LWP module for communicating with Web servers; Bulletproofing servers; Broadcasting and multicasting; and Interprocess communication with UNIX domain sockets.
Useful, working programs demonstrate ideas and techniques in action, including a real-time chat and messaging system, a program for processing e-mail containing MIME attachments, a program for mirroring an FTP site, and a Web robot.
Network Programming with Perl focuses on TCP/IP rather than just the common Web protocols. Modeled after the critically acclaimed TCP/IP Illustrated by W. Richard Stevens, this book achieves a level of detail far superior to most. It is an essential resource for network administrators and Perl programmers who are creating network applications.