如何将来访者的IP及其它信息生成一张图片

如:

页面:

https://i-blog.csdnimg.cn/blog_migrate/523b0827b357088631d6b2ba418af005.png?word=

其实原理很简单,得到来访者的IP/OS/Language/Browser,利用Image/Graphics类进行处理

代码如下:

 1None.gifusing  System;
 2None.gifusing
 System.Collections;
 3None.gifusing
 System.ComponentModel;
 4None.gifusing
 System.Data;
 5None.gifusing
 System.Drawing;
 6None.gifusing
 System.Web;
 7None.gifusing
 System.Web.SessionState;
 8None.gifusing
 System.Web.UI;
 9None.gifusing
 System.Web.UI.WebControls;
10None.gifusing
 System.Web.UI.HtmlControls;
11None.gifusing
 System.IO;
12None.gifnamespace
 WebApplication4
13ExpandedBlockStart.gifContractedBlock.gifdot.gif
{
14InBlock.gif public class
 ip : System.Web.UI.Page
15ExpandedSubBlockStart.gifContractedSubBlock.gif dot.gif
{
16
InBlock.gif  
17InBlock.gif  private void Page_Load(object
 sender, System.EventArgs e)
18ExpandedSubBlockStart.gifContractedSubBlock.gif  dot.gif
{
19InBlock.gif   string str = System.Web.HttpContext.Current.Request.QueryString["word"
];
20InBlock.gif   bool cusWord=false
;
21
InBlock.gif
22InBlock.gif   //如果没有自定义文字则不显示,否则只显示前30位

23InBlock.gif   if((str==null)||(str.Trim().Length==0))
24ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif
{
25InBlock.gif    str = ""
;
26ExpandedSubBlockEnd.gif   }

27InBlock.gif   else
28ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{
29InBlock.gif    if(str.Length>30
)
30ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif
{
31InBlock.gif     str = str.Substring(0,30)+"dot.gif"
;
32ExpandedSubBlockEnd.gif    }

33InBlock.gif    string badword =System.Configuration.ConfigurationSettings.AppSettings["badwords"];
34
InBlock.gif
35InBlock.gif    //过滤不健康词语

36InBlock.gif    for(int i=0;i<badword.Split('|').Length;i++)
37ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif
{
38InBlock.gif     str = str.Replace(badword.Split('|')[i],"[脏话,已被过滤]"
);
39ExpandedSubBlockEnd.gif    }

40InBlock.gif    cusWord=true;
41ExpandedSubBlockEnd.gif   }

42InBlock.gif   //获取来访者的相关信息
43InBlock.gif   string IP = "Your IP:"+Request.UserHostAddress;
44InBlock.gif   string Language = "Language:" + Request.UserLanguages[0
];
45InBlock.gif   string OS = "Your Os:" +
Request.Browser.Platform;
46InBlock.gif   string Browser = "Browser:" + Request.Browser.Browser + " " +
 Request.Browser.Version;
47
InBlock.gif  
48InBlock.gif   //初始化一个Image对象

49InBlock.gif   System.Drawing.Image copyImage = System.Drawing.Image.FromFile(Server.MapPath("ip.jpg"));
50InBlock.gif   Graphics g =
 Graphics.FromImage(copyImage);
51InBlock.gif   g.DrawImage(copyImage, 00
, copyImage.Width, copyImage.Height);
52InBlock.gif   Font f = new Font("courier new",8
,System.Drawing.FontStyle.Bold);
53InBlock.gif   Font f1 = new Font("宋体",9
,System.Drawing.FontStyle.Underline);
54InBlock.gif   Brush b1 = new
 SolidBrush(Color.Blue);
55InBlock.gif   Brush b2 = new
 SolidBrush(Color.Red);
56InBlock.gif   Brush b3 = new
 SolidBrush(Color.Green);
57InBlock.gif   Brush b4 = new
 SolidBrush(Color.Black);
58InBlock.gif   if
(cusWord)
59ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif
{
60InBlock.gif    g.DrawString(str, f1, b4, 805
);
61InBlock.gif    g.DrawString(IP, f, b1, 8018
);
62InBlock.gif    g.DrawString(OS, f, b2, 8030
);
63InBlock.gif    g.DrawString(Language, f, b2, 8042
);
64InBlock.gif    g.DrawString(Browser, f, b3, 8054
);
65ExpandedSubBlockEnd.gif   }

66InBlock.gif   else
67ExpandedSubBlockStart.gifContractedSubBlock.gif   dot.gif{
68InBlock.gif    g.DrawString(IP, f, b1, 8010
);
69InBlock.gif    g.DrawString(OS, f, b2, 8025
);
70InBlock.gif    g.DrawString(Language, f, b2, 8040
);
71InBlock.gif    g.DrawString(Browser, f, b3, 8055
);
72ExpandedSubBlockEnd.gif   }

73InBlock.gif   g.Dispose();
74
InBlock.gif
75InBlock.gif   System.IO.MemoryStream ms = new
 System.IO.MemoryStream();
76
InBlock.gif   copyImage.Save(ms,System.Drawing.Imaging.ImageFormat.Jpeg);
77
InBlock.gif   Response.ClearContent();
78InBlock.gif   Response.ContentType = "image/Jpeg"
;
79
InBlock.gif   Response.BinaryWrite(ms.ToArray());
80
InBlock.gif
81
InBlock.gif
82ExpandedSubBlockEnd.gif  }

83InBlock.gif
84ContractedSubBlock.gifExpandedSubBlockStart.gif  Web
#region Web 
85InBlock.gif  override protected void OnInit(EventArgs e)
86ExpandedSubBlockStart.gifContractedSubBlock.gif  dot.gif
{
87
InBlock.gif   InitializeComponent();
88InBlock.gif   base
.OnInit(e);
89ExpandedSubBlockEnd.gif  }

90InBlock.gif  
91InBlock.gif   private void
 InitializeComponent()
92ExpandedSubBlockStart.gifContractedSubBlock.gif  dot.gif
{   
93InBlock.gif   this.Load += new System.EventHandler(this
.Page_Load);
94
InBlock.gif
95ExpandedSubBlockEnd.gif  }

96ExpandedSubBlockEnd.gif  #endregion

97ExpandedSubBlockEnd.gif }

98ExpandedBlockEnd.gif}

转载于:https://www.cnblogs.com/lemongtree/archive/2005/09/28/245655.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值