Remoting 的服务器侧如何获知Client的IP地址

eaglet 2006-08-14 09:04:44
我在服务器侧想获知连接服务器的客户端的IP地址,以校验其身份,不知如何实现?
...全文
294 11 打赏 收藏 举报
写回复
11 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
szh3210 2007-02-12
mark
  • 打赏
  • 举报
回复
wuluhua2003 2006-12-06
ip地址可以手工改,还是获取mac地址比较好
  • 打赏
  • 举报
回复
moonshineidolon 2006-12-06
去搜索一下探针
  • 打赏
  • 举报
回复
早起晚睡 2006-12-06
我感觉发消息的时候IP地址也是消息的一部分就简单了
  • 打赏
  • 举报
回复
huangyj 2006-12-06
关注!
  • 打赏
  • 举报
回复
hcling03 2006-10-30
使用方法见我在
http://community.csdn.net/Expert/topic/5054/5054452.xml?temp=.6051294
中的描述
  • 打赏
  • 举报
回复
hcling03 2006-10-30
using System;
using System.Runtime.Remoting.Channels;
using System.Net;
using System.Runtime.Remoting.Messaging;
using System.Collections;
using System.IO;

namespace remotingTest
{

public class CClientIPInjectorSinkProvider : IServerChannelSinkProvider
{

private IServerChannelSinkProvider _nextProvider;

public CClientIPInjectorSinkProvider(){}

public CClientIPInjectorSinkProvider(IDictionary properties,
ICollection providerdata){}

public IServerChannelSink CreateSink(IChannelReceiver channel)
{
//create other sinks in the chain
IServerChannelSink nextSink = _nextProvider.CreateSink(channel);
return new CClientIPInjectorSink(nextSink);
}


public void GetChannelData(IChannelDataStore channelData)
{
//not needed
}

public IServerChannelSinkProvider Next
{
get
{
return _nextProvider;
}
set
{
_nextProvider = value;
}
}
}
}
  • 打赏
  • 举报
回复
hcling03 2006-10-30
使用下面的sinkprovider类和sink类。
sing System;
using System.Runtime.Remoting.Channels;
using System.Net;
using System.Runtime.Remoting.Messaging;
using System.Collections;
using System.IO;

namespace remotingTest
{

public class CClientIPInjectorSink : BaseChannelObjectWithProperties,IServerChannelSink
{
private IServerChannelSink _nextSink;

public CClientIPInjectorSink(IServerChannelSink nextSink)
{
_nextSink = nextSink;
}

public void AsyncProcessResponse(IServerResponseChannelSinkStack sinkStack,
object state,
IMessage msg,
ITransportHeaders headers,
Stream stream)
{
//get the client's ip address, and put it in the call context.
//This value will be extracted later so we can determine the actual
//address of the client.
try
{
IPAddress IPAddr = (IPAddress)headers[CommonTransportKeys.IPAddress];
//====================================
Console.WriteLine(IPAddr.ToString());
//====================================
CallContext.SetData("ClientIP", IPAddr);
}
catch{}

//forward to stack for further processing
sinkStack.AsyncProcessResponse(msg, headers,stream);
}

public Stream GetResponseStream(IServerResponseChannelSinkStack sinkStack,
object state,
IMessage msg,
ITransportHeaders headers)
{
return null;
}

public IServerChannelSink NextChannelSink
{
get
{
return _nextSink;
}
}

public ServerProcessing ProcessMessage(IServerChannelSinkStack sinkStack,
IMessage requestMsg,
ITransportHeaders requestHeaders,
Stream requestStream,
out IMessage responseMsg,
out ITransportHeaders responseHeaders,
out Stream responseStream)
{


//get the client's ip address, and put it in the call context.
//This value will be extracted later so we can determine the actual
//address of the client.
try
{
IPAddress IPAddr = (IPAddress)requestHeaders[CommonTransportKeys.IPAddress];
//===================================
Console.WriteLine(IPAddr.ToString());
CallContext.SetData("ClientIP", IPAddr);
}
catch{}

//pushing onto stack and forwarding the call
sinkStack.Push(this,null);

ServerProcessing srvProc =
_nextSink.ProcessMessage(sinkStack,requestMsg,
requestHeaders, requestStream,
out responseMsg,out responseHeaders,
out responseStream);
if(srvProc == ServerProcessing.Complete)
{
//TODO - implement post processing
}
return srvProc;
}
}
}
  • 打赏
  • 举报
回复
califord 2006-08-25
string ipAddress = System.Web.HttpContext.Current.Request.UserHostAddress
  • 打赏
  • 举报
回复
htu 2006-08-17
我也想知道,帮你顶以下
  • 打赏
  • 举报
回复
相关推荐
发帖
C#
加入

10.7w+

社区成员

.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
申请成为版主
帖子事件
创建了帖子
2006-08-14 09:04
社区公告

让您成为最强悍的C#开发者