存档

‘.NET’ 分类的存档

Whois简易查询Android版

2011年11月29日 admin 1 条评论

有空玩了下android,配置环境比较啰嗦。google下
贴效果图;

效果简单 之前是模仿了cnblog的一篇文章。不过他是抓url。我是用socket。
后缀还没细分,喜欢的人自己研究去,贴代码

public class MyWhois extends Activity {
	private TextView vResult;
	private EditText eKeyWord;
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
 
        Button sButton1 = (Button)findViewById(R.id.Submit); 
        vResult = (TextView)findViewById(R.id.ResultView);
    	eKeyWord = (EditText)findViewById(R.id.KeyWord); 
 
        //注册点击事件监听者  
        sButton1.setOnClickListener(new OnClickListener()
        {
            public void onClick(View aView) { 
            	TextView vResult = (TextView)findViewById(R.id.ResultView);
            	vResult.setText("正在查询中,请稍等!");
 
            	//新建查询线程,否则UI界面会假死
            	Thread mThread = new Thread(new Runnable() {
            		public void run() {  
            			String whoisMes="";
                    	  try {
                    		  try
                 		     {
                 			   String domain=eKeyWord.getText().toString();
                 			   String IP="whois.cnnic.cn";
                 			   if(domain.contains(".com")||domain.contains(".com")){
                 				   IP="whois.internic.net";
                 			   }				   
                 		       Socket socket = new Socket(IP, 43);
                 		       InputStream Is = socket.getInputStream();
                 		       OutputStream Os = socket.getOutputStream();
                 		       DataInputStream DIS = new DataInputStream(Is);
                 		       PrintStream PS = new PrintStream(Os);
                 		       DataInputStream in = new DataInputStream(System.in);		      
                 		       PS.println(domain);
                 		       System.out.println("please wait whois's message...");
 
                 		       boolean TF = false;
 
                 		       while (DIS.read() > 0) {
                 		         String tempStr = DIS.readLine();
                 		        whoisMes = whoisMes + tempStr + "\r\n";
                 		       }
                 		       whoisMes=new String(whoisMes.getBytes("ISO-8859-1"),"utf-8");
                 		       System.out.println(whoisMes);
                 		       DIS.close();
                 		       PS.close();
                 		       Is.close();
                 		       Os.close();
                 		       socket.close();
                 		     } catch (Exception e) {
                 		       System.out.println("Error:" + e);
                 		     }
                    		  //返回的数据需要使用'\n'来换行!
                    		            Message mg = Message.obtain();  
                    		            mg.obj = whoisMes;  
                    		            mHandler.sendMessage(mg);  
 
                    		  } catch (Exception e) {
                    		   e.printStackTrace();
                    		  }
            		}
 
            	});
            	 mThread.start();  
            }
        }
 
        ); 
    }
 
    //定义一个Handler  
    private Handler mHandler = new Handler(){  
        public void handleMessage(Message msg){  
        	String m = (String) msg.obj;
        	if(m.length()<=0)
        	{
        		vResult.setText("查询结果为空.");
        	}
        	else
        	{
        		vResult.setText(m);
        	}
        }  
    };  
}
分类: .NET 标签: ,

execl操作2张表对应 vlookup

2011年8月8日 admin 1 条评论

如何将两个工作表整合在一各工作表中

excel中有两个工作表sheet1.2。第一个表有姓名和身份证号/第二个表有姓名和ID号。现在如何将姓名、ID号、身份证号整合在sheet3中呢?(注:前两个工作表中的名字顺序都不同但是名字和ID号是对应的和身份证号也是对应的。)

表1 里A列是名字,B列是身份证号,表 2 里A列是名字,B列是ID,在表2的C1单元格里写=VLOOKUP(A1,Sheet1!A:B,2,0),然后向下填充就行了。

excel两个vlookup函数表达的异同。 如何将两个工作表整合在一各工作表中 – 木棉花 – 木棉花的博客

“=VLOOKUP(A1,Sheet1!$A$1:$B$5,2)”与“=VLOOKUP(A1,Sheet1!A:B,2,0)”

有人说这俩公式中,后一个可能引发错误,因此不能用于跨表的情况。那么请问,后一个为什么会出错啊?

请就我给出的两个函数有针对性的作答吧,这种普适性的回答实在让人没有办法理解啊!

1、在同一工作簿中可跨表使用,两个公式均可。

2、在“=VLOOKUP(A1,Sheet1!$A$1:$B$5,2)”中,当Sheet1中插入A列时,原A、B列就成了B、C列,此公式仍有效,可不变。我喜欢这种。

3、不过“=VLOOKUP(A1,Sheet1!A:B,2,0)”就只适用原A、B列不变的情况。

、“=VLOOKUP(A1,Sheet1!$A$1:$B$5,2)”
正确为:
1、=VLOOKUP(A1,Sheet1!$A$1:$B$5,2,0)

2、“=VLOOKUP(A1,Sheet1!A:B,2,0)”公式正确。

两个公式向下复制时,都正确的有返回值;
公式(1)向右复制时,都正确的有返回值;
公式(2)向右复制时,没有正确的返回值。

公式(1)的查找区域是绝对的;
公式(2)的查找区域是相对的。

分类: .NET 标签: ,

遍历获取枚举值数组

2011年5月3日 admin 没有评论

foreach (DomainlistInfo.DomainStatus item in (DomainlistInfo.DomainStatus[])Enum.GetValues(typeof(DomainlistInfo.DomainStatus)))
{
b_status.Items.Add(new ListItem(item.ToString(), Convert.ToString((int)item)));
}
绑定enum的值 这样 就不用搞数组了
下面这篇文章非常好用

http://www.yaosansi.com/post/1375.html

分类: .NET 标签:

无法在类…中找到资源***.bmp

2011年5月3日 admin 没有评论

WinForm写的一个程序,在项目中添加了一个bmp图片,然后
Bitmap b = new Bitmap(GetType(),”close.bmp”);
“无法在类…中找到资源close.bmp”,无论是新建bmp图片还是引用现有bmp图片都会在运行时找不到
解决方法:
右键图片属性:生成操作 选择“嵌入的资源”

分类: .NET 标签:

Wcf 无法处理消息。这很可能是因为操作

2011年5月3日 admin 没有评论

这个问题 在本地写好的wcf服务端 用客户端调试是没有问题的 一旦上传到
服务器就有这个问题。
第一个问题“无法满足对安全令牌的请求,因为身份验证失败”;
然后在客户端的security 改成security mode=”None” 。但还是会冒
“法处理消息。这很可能是因为操作“http://tempuri.org/****”不正确,
或因为消息包含无效或过期的安全上下文令牌,或因为绑定之间出现不匹配。
如果由于未处于活动状态导致服务中止了该通道,则安全上下文令牌无效。
若要防止服务永久中止闲置会话,请增加服务终结点绑定上的接收超时。”
这个应该就是服务端没配置好,那么服务端该如何配置 关键一句:
服务器Config文件,添加

<system.serviceModel>
 
 <bindings>
        <wsHttpBinding>
          <binding name="httpconf">
            <security mode="None">
              <transport clientCredentialType="Windows"/>
              <message clientCredentialType="Windows"/>
            </security>
          </binding>
        </wsHttpBinding>
 </bindings>
 
</system.serviceModel>
 
然后配置终结点属性
 
<endpoint address="" binding="wsHttpBinding" contract="ConsoleApplication1.IService1"  bindingConfiguration="httpconf">
            <identity>
              <dns value="localhost" />
            </identity>
          </endpoint>

链接网址:

extjs-xtype定义错误

2011年5月3日 admin 没有评论

types[config.xtype || defaultType] is not a constructor
错误原因 xtype定义错误
extjs 不能运行在asp.net的含form的html内

分类: .NET 标签:

Peid查看软件开发语言

2011年3月24日 admin 没有评论

Peid查看软件开发语言 点此下载

分类: .NET 标签:

近段感想

2011年3月23日 admin 没有评论

[环境]早上骑着自行车的时候,经常看着那些汽车。经常会在想这样一个问题,同样是24小时,为什么他获得的收益却要比我的大这么
多。抛开一些非公平因素,如富二代,拆迁暴富,还是有很多的人是通过双手创造财富的,那么我和他们的差距在哪里。我创造
的价值和他们创造的价值差距为什么这么大。我们必须承认,我们的社会局部是非常不公平的,但是总体却是公平的。只有客观的认识
环境,才能摆正自己的位置,找到你自己的汽车。

[想法]一个人一定要有自己的想法,没有想法如同行尸走肉,做一天和尚撞一天钟。我有个同学他很有想法,让我钦佩。09年在groupon
在国外刚兴起的时候,他也想借鉴这个模仿,那时候找到我问我做这个网站难不难。我跟他说不难,他就注册了一个团购域名暑假里和一些
同学一起干了起来。后来由于种种原因没有成功。前几个月,他和另外三个人再次创业,合开了个工作室做手机应用。也是很热门的一个
方向。着实让我震惊了一把,我都已经工作了2年多了什么想法都没有,他还在上学(读研),却已经开始了创业生涯。虽然现在没有成功,
但是我相信是迟早的事情。我们每个人都扪心自问下:你是否还有自己的理想?那目标呢?实在没有,给点想法也行。

[实干]有了想的,当然要去做。有些人老是埋怨自己入错行,没有机遇,运气不好,家里没背景。不需要抱怨,抱怨一点用都没有,只
需要认清事实。既然没有这些客观条件,那么就让自己双手去创造。脚踏实地的去做,上帝迟早回来眷顾你的。去做了才有可能获得成功,
即使失败也是坦然面对,“我自横刀向天笑,留取肝胆两昆仑”。如果只是想,今天想创业,明天想发财,那都是空想。Just wast time.很
多大企业或企业当初创业的时候 都是微不足道的一个想法,但是如果没人去做,那么他根本就不会存在。

[坚持]其实我也有很多的想法,我也尝试了去做。做过垃圾站,写过企业软件,开源程序,但都是没有成功。原因很简单,就是不够坚持。任何一
件事情,只要认准了那就坚持着去做。终究会有所收获的。很多人做做垃圾站都月入上w,创造财富的事迹到处都是,唯独没有你的一份,那么
我想肯定是你不够坚持。

[一颗永不服输的心]以前我在学校里,虽然我不是非常聪明的那种,但我一定是绝不服输的那种。别人能考到的,我也一定可以,我会
花更多的时间,更多的认真去拼。现在社会里,诚然没有学校里的那种公平环境,但是绝不能甘于人后。别人有的,现在我没有,但是以后
我一定会有!成功的道路上失败在所难免,But Never Give Up!

分类: .NET 标签:

哪本书是对程序员最有影响、每个程序员都该阅读的书?

2011年3月15日 admin 没有评论

 国外知名网站stackoverflow上有一个问题调查: 哪本书是对程序员最有影响、每个程序员都该阅读的书?,这个调查已历时两年,目前为止吸引了153,432人访问,读者共推荐出了478本书(还在增加),其中最火的一本书《Code Complete》(代码大全)被顶了1306次。如果你是个程序员,你一定有兴趣看看这些书里你都看过几本,如果你一本没看过的话,我也不好说什么,也许你是个天才,但我相信大多数人都知道,你在学校里根本学不到什么真正的工作中需要的知识,我们毕业后能帮助我们在公司中胜任工作的老师就是这些优秀的书籍,一本好书可以改变一个人的一生。

  下面是这个调查中排名靠前的书的一个简单的清单:

1. 第一名:1306票《Code Complete (2nd Ed) by Steve McConnell》,中文版《代码大全(第二版)》,两届Software Jolt Award震撼大奖得主!
cover
2. 第二名:1161票《The Pragmatic Programmer》,中文版《程序员修炼之道》
The Pragmatic Programmer
3. 第三名:689票《Structure and Interpretation of Computer Programs》,中文版《计算机程序的构造和解释》
Structure and Interpretation of Computer Programs – 2nd Edition (MIT Electrical Engineering and Computer Science)
4. 第四名:557票《The C Programming Language》,中文版《C程序设计语言》
The C Programming Language Book
5. 第五名:472票《Refactoring: Improving the Design of Existing Code》,中文版《重构:改善既有代码的设计》
Refactoring: Improving the Design of Existing Code
6. 第六名:472票《Introduction to algorithms》,中文版《算法导论》
Introduction to algorithms cover image
7. 第七名:430票《The Mythical Man-Month》,中文版《人月神话》
The Mythical Man-Month: Essays on Software Engineering, Anniversary Edition (2nd Edition)
8. 第八名:426票《Design Patterns》,中文版《设计模式》
9. 第九名:386票《The Art of Computer Programming(First Volume Hardcover)》,中文版《计算机程序设计艺术第(第一卷)》

http://www.aqee.net/wordpress/wp-content/uploads/2011/03/75dd9_programming_41T1XCAEE1L.jpg

10. 第10名:353票《Compilers: Principles, Techniques, and Tools 》,中文版《编译原理》
Compilers: Principles, Techniques, and Tools (2nd Edition)
11. 第11名:329票《Head-First Design Patterns》,中文版《Head First 设计模式》

  当然了,这里的排名并不具有什么权威性,但绝对可以说都是好书,这11本外还有很多书虽然票数不是那么多,但大家估计都耳熟能详,比如《Effective C++》(中文版《Effective C++:改善程序与设计的55个具体做法》),《Clean Code》(中文版《代码整洁之道》),《Effective Java》(中文版《Effective Java中文版(第2版)》等。

  记得有位先哲曾说过:一种编程语言的重要性并不在于语言本身,而是在于这种语言来体现出来的编程思维模式。所以说,并不是你用到的书才去读,读书是一种习惯。

  英文原文: What is the single most influential book every programmer should read?

分类: .NET 标签: ,

.net 操作IIS IP

2011年3月12日 admin 没有评论

我们在应对网站的恶意请求时候,一个解决方法就是把有问题的请求IP封杀掉。

如果想快速处理这种问题,就需要编写一段代码,达到一定门槛,自动封杀。再复杂点就是不是永久封杀,还可以自动在一定时间后解封。

封杀的逻辑代码看后面提供的。

需要说明的是:IIS7时,情况发生了不同。

下面的代码,在处理封杀IP时候,不论IIS6还是IIS7 都可以把需要封杀的IP加入封杀列表。但是需要注意的是我们代码写的是全部替换原先的数据。但是在IIS7下,执行的效果是原先的不替换,新加一批封杀 IP。当然IIS7下,如果新加的IP原来就有了,则会报如下异常:

System.Runtime.InteropServices.COMException was caught
Message=”当文件已存在时,无法创建该文件。 (异常来自 HRESULT:0x800700B7)”
Source=”System.DirectoryServices”
ErrorCode=-2147024713
StackTrace:
在 System.DirectoryServices.DirectoryEntry.CommitChanges()
在 IIS_Security_ConsoleApplication.Program.IPDeny() 位置 D:\MyCodes\IIS_Security_ConsoleApplication \IIS_Security_ConsoleApplication\Program.cs:行号 109
InnerException:

这就是说,IIS7, 我们可以通过编程接口增加封杀IP名单,但是没发通过编程接口剔出封杀IP。

参考代码:

这里提供了两套参考代码,其实原理都是一样的。

在IIS 6 下,都没有任何问题, IIS 7 下都会有没发删除原先已有数据的问题。

代码一:

 
    using System.DirectoryServices;
    using System.Reflection;
    using System;
 
    class Program
    {
 
        static void IPDeny()
        {
 
            try
            {
                string serverName = "localhost";
                // retrieve the directory entry for the root of the IIS server
                System.DirectoryServices.DirectoryEntry IIS = new System.DirectoryServices.DirectoryEntry(
                     string.Format("IIS://{0}/w3svc/1/root", serverName));
 
                // retrieve the list of currently denied IPs
                Console.WriteLine("Retrieving the list of currently denied IPs.");
 
                // get the IPSecurity property
                Type typ = IIS.Properties["IPSecurity"][0].GetType();
                object IPSecurity = IIS.Properties["IPSecurity"][0];
 
 
                // retrieve the IPDeny list from the IPSecurity object
                Array origIPDenyList = (Array)typ.InvokeMember("IPDeny", BindingFlags.DeclaredOnly | BindingFlags.Public 
                    | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetProperty, null, IPSecurity, null);
 
                // 罗列已经被拒绝的地址
                foreach (string s in origIPDenyList)
                    Console.WriteLine("Before: " + s);
 
                // check GrantByDefault.  This has to be set to true, 
                // or what we are doing will not work.
                bool bGrantByDefault = (bool)typ.InvokeMember("GrantByDefault", BindingFlags.DeclaredOnly | BindingFlags.Public 
                    | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetProperty, null, IPSecurity, null);
 
                Console.WriteLine("GrantByDefault = " + bGrantByDefault);
                if (!bGrantByDefault)
                {
                    // 必须设置  默认允许访问
                    typ.InvokeMember("GrantByDefault", BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic 
                        | BindingFlags.Instance | BindingFlags.SetProperty, null, IPSecurity, new object[] { true });
                }
 
 
                // 更新被拒绝的IP列表
                // 注意这里是完全替换
                // 如果你想保留原先的拒绝列表,需要原先的拒绝列表也在这个数组中
 
                Console.WriteLine("Updating the list of denied IPs.");
 
                object[] newIPDenyList = new object[4];
                newIPDenyList[0] = "192.168.1.21, 255.255.255.255";
                newIPDenyList[1] = "192.168.1.22, 255.255.255.255";
                newIPDenyList[2] = "192.168.1.23, 255.255.255.255";
                newIPDenyList[3] = "192.168.1.24, 255.255.255.255";
 
                Console.WriteLine("Calling SetProperty");
 
                // add the updated list back to the IPSecurity object
                typ.InvokeMember("IPDeny", BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic 
                    | BindingFlags.Instance | BindingFlags.SetProperty, null, IPSecurity, new object[] { newIPDenyList });
 
 
 
                IIS.Properties["IPSecurity"][0] = IPSecurity;
 
                Console.WriteLine("Commiting the changes.");
 
                // commit the changes
                IIS.CommitChanges();
                IIS.RefreshCache();
 
                // 检查更新后的数据
                Console.WriteLine("Checking to see if the update took.");
 
                IPSecurity = IIS.Properties["IPSecurity"][0];
                Array y = (Array)typ.InvokeMember("IPDeny",
                          BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance 
                          | BindingFlags.GetProperty, null, IPSecurity, null);
 
                foreach (string s in y)
                    Console.WriteLine("After:  " + s);
            }
            catch (Exception e)
            {
                Console.WriteLine("Error: " + e.ToString());
            }
 
        }
    }

代码二:

        using System.DirectoryServices;
        using System.Reflection;
        using System;
 
 
 
 
        static void SetIPSecurityProperty(string metabasePath, string member, string item)
        {
            //  metabasePath is of the form "IIS://<servername>/<path>"
            //    for example "IIS://localhost/SMTPSVC/1" 
            //  member is of the form "IPGrant|IPDeny|DomainGrant|DomainDeny"
            //  item is of the form "<ipaddress|domain>", for example, 157.56.236.15 or domain.microsoft.com
            Console.WriteLine("\nEnumerating the IPSecurity property at {0}:", metabasePath);
 
            try
            {
                if (("IPGrant" != member) && ("IPDeny" != member) && ("DomainGrant" != member) && ("DomainDeny" != member))
                {
                    Console.WriteLine(" Failed in SetIPSecurityProperty; second param must be one of IPGrant|IPDeny|DomainGrant|DomainDeny");
                }
                else
                {
                    DirectoryEntry path = new DirectoryEntry(metabasePath);
                    path.RefreshCache();
                    object ipsecObj = path.Invoke("Get", new string[] { "IPSecurity" });
                    Type t = ipsecObj.GetType();
                    Array data = (Array)t.InvokeMember(member, BindingFlags.GetProperty, null, ipsecObj, null);
                    Console.WriteLine(" Old {0} =", member);
                    bool exists = false;
                    foreach (object dataItem in data)
                    {
                        Console.WriteLine("  {0}", dataItem.ToString());
                        if (dataItem.ToString().StartsWith(item))
                        {
                            exists = true;
                        }
                    }
 
                    if (exists)
                    {
                        Console.WriteLine(" {0} already exists in {1}", item, member);
                    }
                    else
                    {
                        object[] newData = new object[data.Length + 1];
                        data.CopyTo(newData, 0);
                        newData.SetValue(item, data.Length);
 
                        t.InvokeMember(member, BindingFlags.SetProperty, null, ipsecObj, new object[] { newData });
 
                        path.Invoke("Put", new object[] { "IPSecurity", ipsecObj });
 
                        path.CommitChanges();
 
                        path.RefreshCache();
                        ipsecObj = path.Invoke("Get", new string[] { "IPSecurity" });
                        data = (Array)t.InvokeMember(member, BindingFlags.GetProperty, null, ipsecObj, null);
                        Console.WriteLine(" New {0} =", member);
                        foreach (object dataItem in data)
                            Console.WriteLine("  {0}", dataItem.ToString());
                        Console.WriteLine(" Done.");
                    }
                }
            }
            catch (Exception ex)
            {
                if ("HRESULT 0x80005006" == ex.Message)
                    Console.WriteLine(" Property IPSecurity does not exist at {0}", metabasePath);
                else
                    Console.WriteLine("Failed in SetIPSecurityProperty with the following exception: \n{0}", ex.Message);
            }
        }
 
        static void Main(string[] args)
        {
 
            // 获取目前服务器上有哪些站点
            DirectoryEntry root = new DirectoryEntry("IIS://localhost/W3SVC");
            foreach (DirectoryEntry dir in root.Children)
            {
                if (dir.SchemaClassName == "IIsWebServer")
                {
                    string ww = dir.Properties["ServerComment"].Value.ToString();
 
                    Console.Write("IIS://localhost/W3SVC/{0}/ROOT/  {1}\r\n", dir.Name, ww);
                }
            }
 
 
            // IPDeny();
 
            SetIPSecurityProperty("IIS://localhost/w3svc/1/root", "IPDeny", "192.168.5.79");
 
            Console.ReadLine();
        }

原文链接 http://www.supesoft.com/ArticleDisp.asp?ID=4598&Cmd=Print