473,224 Members | 1,900 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,224 software developers and data experts.

getting client ip in sock-client on server

The code of classes given below is for server to which clients connect
i want to get ip address of client which has connected
pls help how can i get
//listen class
public class listen
{
TcpListener server=null;
Thread tcpthread=null;
client[] cl=new client[3];

public listen()
{
//
// TODO: Add constructor logic here
//
}
public void startlisten()
{
Int32 port = 3310;
IPAddress localAddr = IPAddress.Parse("192.168.0.6");

// TcpListener server = new TcpListener(port);
server = new TcpListener(localAddr, port);

// Start listening for client requests.
server.Start();
// Enter the listening loop.
for(int i=0;i<3;i++)
{
cl[i]=new client();
cl[i].status=true;
}

Boolean flag;
while(true)
{
try
{
flag=false;
// Perform a blocking call to accept requests.
// You could also user server.AcceptSocket() here.
for(int i=0;i<3;i++)
{
if(cl[i].status==true)
{
cl[i]= new client(server.AcceptTcpClient());
tcpthread=new Thread(new ThreadStart(cl[i].getClient));
tcpthread.Start();
flag=true;
break;
}
}
if(flag!=true)
{
//MessageBox.Show("All Clients Busy");

}


}
catch(Exception se)
{

}
}

}
public void stoplisten()
{
server.Stop();
}
}


//client class
public class client
{
TcpClient tcpClient;
public Boolean status;
// Buffer for reading data
Byte[] bytes = new Byte[256];
String data = null;
IPAddress localAddr = IPAddress.Parse("192.168.0.6");

public client()
{ //
// TODO: Add constructor logic here
//
//status=true;
}
public client(TcpClient Client)
{
tcpClient =Client;
//
// TODO: Add constructor logic here
//
status=false;
}
public void getClient()
{
try
{
data = null;
// Get a stream object for reading and writing
NetworkStream stream = tcpClient.GetStream();
int i;
// Loop to receive all the data sent by the client.
while((i = stream.Read(bytes, 0, bytes.Length))!=0)
{
// Translate data bytes to a ASCII string.
data = System.Text.Encoding.ASCII.GetString(bytes, 0, i);
// Process the data sent by the client.
string replyMsg = data;
clamdCommand x=new clamdCommand();
replyMsg=x.Command(replyMsg);
int
lowerport=int.Parse(ConfigurationSettings.AppSetti ngs.Get("lowerport"));
int
upperport=int.Parse(ConfigurationSettings.AppSetti ngs.Get("upperport"));
for(int y=lowerport;y<upperport;y++)
{
if(replyMsg==y.ToString())
{
replyMsg=replyMsg+"\r\n\0";
byte[] msg = System.Text.Encoding.ASCII.GetBytes(replyMsg);
// Send back a response.
stream.Write(msg, 0, msg.Length);
TcpListener listener=new TcpListener(localAddr,y);
listener.Start();
// Buffer for reading data
Byte[] bs = new Byte[256];
String ds = null;
// Enter the listening loop.
while(true)
{ // Perform a blocking call to accept requests.
// You could also user server.AcceptSocket() here.
TcpClient bufferclient = listener.AcceptTcpClient();
ds = null;
// Get a stream object for reading and writing
NetworkStream strm = bufferclient.GetStream();
int l;
// Loop to receive all the data sent by the client.
while((l = strm.Read(bs, 0, bs.Length))!=0)
{ ds = System.Text.Encoding.ASCII.GetString(bs, 0, l);
// Process the data sent by the client.
clamresults obj=new clamresults();
ds=obj.loadDatabase("STREAM",ds);

replyMsg=ds;
bufferclient.Close();
break;
}
listener.Stop();
x.freeport(y-lowerport);
break;
} break;
}

}
replyMsg=replyMsg+"\r\n\0";
byte[] msgs = System.Text.Encoding.ASCII.GetBytes(replyMsg);
// Send back a response.
stream.Write(msgs, 0, msgs.Length);

}
}
catch(Exception se)
{
MessageBox.Show(se.ToString());

}
// Shutdown and end connection
finally
{
tcpClient.Close();
status=true;
}
}

}
Jan 19 '06 #1
14 4405
DNS.Resolve()
Jan 19 '06 #2
will it give ip address of client
i want to fetch ip address on server of client which is accepted or
connected
"Marko Becirevic" <ma*****************@inMail24.com> wrote in message
news:dq**********@sunce.iskon.hr...
DNS.Resolve()

Jan 19 '06 #3

"Ankit Aneja" <ef*****@newsgroups.nospam> wrote in message
news:Oz**************@TK2MSFTNGP15.phx.gbl...
will it give ip address of client
i want to fetch ip address on server of client which is accepted or
connected

....

No, it won't. I can't find anything in TcpClient documentation (fw 1.1)
class that would reveal client's IP address (but I may be wrong here) . If
you can use Socket class, then you can use RemoteEndPoint property.

Regards,
Goran
Jan 19 '06 #4

No, it won't. I can't find anything in TcpClient documentation (fw 1.1)
class that would reveal client's IP address (but I may be wrong here)

can i get it using framework 2.0
pls help


"Goran Sliskovic" <gs******@yahoo.com> wrote in message
news:e0**************@TK2MSFTNGP10.phx.gbl...

"Ankit Aneja" <ef*****@newsgroups.nospam> wrote in message
news:Oz**************@TK2MSFTNGP15.phx.gbl...
will it give ip address of client
i want to fetch ip address on server of client which is accepted or
connected

...

No, it won't. I can't find anything in TcpClient documentation (fw 1.1)
class that would reveal client's IP address (but I may be wrong here) . If
you can use Socket class, then you can use RemoteEndPoint property.

Regards,
Goran

Jan 19 '06 #5
can i get remote endpoint in TcpClient if i use framework2.0
"Goran Sliskovic" <gs******@yahoo.com> wrote in message
news:e0**************@TK2MSFTNGP10.phx.gbl...

"Ankit Aneja" <ef*****@newsgroups.nospam> wrote in message
news:Oz**************@TK2MSFTNGP15.phx.gbl...
will it give ip address of client
i want to fetch ip address on server of client which is accepted or
connected

...

No, it won't. I can't find anything in TcpClient documentation (fw 1.1)
class that would reveal client's IP address (but I may be wrong here) . If
you can use Socket class, then you can use RemoteEndPoint property.

Regards,
Goran

Jan 19 '06 #6
Hi Ankit,

In this current situation, I suggest you could try to invoke getpeername /
getsockname using PInvoke mechanism. On a connected socket, getpeername
will give you the remote address and getsockname will give you the local
address for the connection. We could use Socket.Handle Property to get the
socket handle and pass it into these API as parameters.

I hope the above inforamtion is helpful for you.If you have any questions
or concerns, please let me know. Thanks again and have a nice day!

Best Regards,

Terry Fei[MSFT]
Microsoft Community Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Best Regards,

--------------------
From: "Ankit Aneja" <ef*****@newsgroups.nospam>
References: <uq**************@TK2MSFTNGP14.phx.gbl> <dq**********@sunce.iskon.hr> <Oz**************@TK2MSFTNGP15.phx.gbl>
<e0**************@TK2MSFTNGP10.phx.gbl>Subject: Re: getting client ip in sock-client on server
Date: Thu, 19 Jan 2006 19:18:12 +0530
Lines: 30
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
X-RFC2646: Format=Flowed; Original
Message-ID: <Ox**************@TK2MSFTNGP09.phx.gbl>
Newsgroups: microsoft.public.dotnet.languages.csharp
NNTP-Posting-Host: dsl-del-dynamic-067.85.246.61.touchtelindia.net 61.246.85.67Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP09.phx.gbl
Xref: TK2MSFTNGXA02.phx.gbl microsoft.public.dotnet.languages.csharp:379684
X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
No, it won't. I can't find anything in TcpClient documentation (fw 1.1)
class that would reveal client's IP address (but I may be wrong here)

can i get it using framework 2.0
pls help


"Goran Sliskovic" <gs******@yahoo.com> wrote in message
news:e0**************@TK2MSFTNGP10.phx.gbl...

"Ankit Aneja" <ef*****@newsgroups.nospam> wrote in message
news:Oz**************@TK2MSFTNGP15.phx.gbl...
will it give ip address of client
i want to fetch ip address on server of client which is accepted or
connected

...

No, it won't. I can't find anything in TcpClient documentation (fw 1.1)
class that would reveal client's IP address (but I may be wrong here) . If you can use Socket class, then you can use RemoteEndPoint property.

Regards,
Goran



Jan 20 '06 #7
is there anything in framework 2.0
to get the remote address
""TerryFei"" <v-******@online.microsoft.com> wrote in message
news:9G**************@TK2MSFTNGXA02.phx.gbl...
Hi Ankit,

In this current situation, I suggest you could try to invoke getpeername /
getsockname using PInvoke mechanism. On a connected socket, getpeername
will give you the remote address and getsockname will give you the local
address for the connection. We could use Socket.Handle Property to get the
socket handle and pass it into these API as parameters.

I hope the above inforamtion is helpful for you.If you have any questions
or concerns, please let me know. Thanks again and have a nice day!

Best Regards,

Terry Fei[MSFT]
Microsoft Community Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Best Regards,

--------------------
From: "Ankit Aneja" <ef*****@newsgroups.nospam>
References: <uq**************@TK2MSFTNGP14.phx.gbl>

<dq**********@sunce.iskon.hr> <Oz**************@TK2MSFTNGP15.phx.gbl>
<e0**************@TK2MSFTNGP10.phx.gbl>
Subject: Re: getting client ip in sock-client on server
Date: Thu, 19 Jan 2006 19:18:12 +0530
Lines: 30
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
X-RFC2646: Format=Flowed; Original
Message-ID: <Ox**************@TK2MSFTNGP09.phx.gbl>
Newsgroups: microsoft.public.dotnet.languages.csharp
NNTP-Posting-Host: dsl-del-dynamic-067.85.246.61.touchtelindia.net

61.246.85.67
Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP09.phx.gbl
Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.languages.csharp:37968 4
X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
No, it won't. I can't find anything in TcpClient documentation (fw 1.1)
class that would reveal client's IP address (but I may be wrong here)

can i get it using framework 2.0
pls help


"Goran Sliskovic" <gs******@yahoo.com> wrote in message
news:e0**************@TK2MSFTNGP10.phx.gbl...

"Ankit Aneja" <ef*****@newsgroups.nospam> wrote in message
news:Oz**************@TK2MSFTNGP15.phx.gbl...
will it give ip address of client
i want to fetch ip address on server of client which is accepted or
connected
...

No, it won't. I can't find anything in TcpClient documentation (fw 1.1)
class that would reveal client's IP address (but I may be wrong here) . If you can use Socket class, then you can use RemoteEndPoint property.

Regards,
Goran


Jan 20 '06 #8
Hi Ankit,
Thanks for your quick response!
is there anything in framework 2.0 to get the remote address? Based on my knowledge, there is no this feature in framework 2.0. But I'll
consult this question for the relevant team. If I have an easier way to
achieve this goal later, I'll inform of you as soon as possible.
Thanks for your understanding!

Best Regards,

Terry Fei[MSFT]
Microsoft Community Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
From: "Ankit Aneja" <ef*****@newsgroups.nospam>
References: <uq**************@TK2MSFTNGP14.phx.gbl> <dq**********@sunce.iskon.hr> <Oz**************@TK2MSFTNGP15.phx.gbl>
<e0**************@TK2MSFTNGP10.phx.gbl>
<Ox**************@TK2MSFTNGP09.phx.gbl>
<9G**************@TK2MSFTNGXA02.phx.gbl>Subject: Re: getting client ip in sock-client on server
Date: Fri, 20 Jan 2006 10:47:03 +0530
Lines: 81
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
X-RFC2646: Format=Flowed; Original
Message-ID: <uA*************@tk2msftngp13.phx.gbl>
Newsgroups: microsoft.public.dotnet.languages.csharp
NNTP-Posting-Host: dsl-del-dynamic-130.84.246.61.touchtelindia.net 61.246.84.130Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msft ngp13.phx.gbl
Xref: TK2MSFTNGXA02.phx.gbl microsoft.public.dotnet.languages.csharp:379924
X-Tomcat-NG: microsoft.public.dotnet.languages.csharp

is there anything in framework 2.0
to get the remote address
""TerryFei"" <v-******@online.microsoft.com> wrote in message
news:9G**************@TK2MSFTNGXA02.phx.gbl...
Hi Ankit,

In this current situation, I suggest you could try to invoke getpeername

/ getsockname using PInvoke mechanism. On a connected socket, getpeername
will give you the remote address and getsockname will give you the local
address for the connection. We could use Socket.Handle Property to get the socket handle and pass it into these API as parameters.

I hope the above inforamtion is helpful for you.If you have any questions
or concerns, please let me know. Thanks again and have a nice day!

Best Regards,

Terry Fei[MSFT]
Microsoft Community Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Best Regards,

--------------------
From: "Ankit Aneja" <ef*****@newsgroups.nospam>
References: <uq**************@TK2MSFTNGP14.phx.gbl>

<dq**********@sunce.iskon.hr> <Oz**************@TK2MSFTNGP15.phx.gbl>
<e0**************@TK2MSFTNGP10.phx.gbl>
Subject: Re: getting client ip in sock-client on server
Date: Thu, 19 Jan 2006 19:18:12 +0530
Lines: 30
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
X-RFC2646: Format=Flowed; Original
Message-ID: <Ox**************@TK2MSFTNGP09.phx.gbl>
Newsgroups: microsoft.public.dotnet.languages.csharp
NNTP-Posting-Host: dsl-del-dynamic-067.85.246.61.touchtelindia.net

61.246.85.67
Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP09.phx.gbl
Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.languages.csharp:3796 84
X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
No, it won't. I can't find anything in TcpClient documentation (fw 1.1)
class that would reveal client's IP address (but I may be wrong here)

can i get it using framework 2.0
pls help


"Goran Sliskovic" <gs******@yahoo.com> wrote in message
news:e0**************@TK2MSFTNGP10.phx.gbl...

"Ankit Aneja" <ef*****@newsgroups.nospam> wrote in message
news:Oz**************@TK2MSFTNGP15.phx.gbl...
> will it give ip address of client
> i want to fetch ip address on server of client which is accepted or
> connected
...

No, it won't. I can't find anything in TcpClient documentation (fw 1.1)
class that would reveal client's IP address (but I may be wrong here) .

If
you can use Socket class, then you can use RemoteEndPoint property.

Regards,
Goran




Jan 20 '06 #9
Thanks Sir
will wait for your reply
""TerryFei"" <v-******@online.microsoft.com> wrote in message
news:7Q**************@TK2MSFTNGXA02.phx.gbl...
Hi Ankit,
Thanks for your quick response!
is there anything in framework 2.0 to get the remote address? Based on my knowledge, there is no this feature in framework 2.0. But I'll
consult this question for the relevant team. If I have an easier way to
achieve this goal later, I'll inform of you as soon as possible.
Thanks for your understanding!

Best Regards,

Terry Fei[MSFT]
Microsoft Community Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
From: "Ankit Aneja" <ef*****@newsgroups.nospam>
References: <uq**************@TK2MSFTNGP14.phx.gbl>

<dq**********@sunce.iskon.hr> <Oz**************@TK2MSFTNGP15.phx.gbl>
<e0**************@TK2MSFTNGP10.phx.gbl>
<Ox**************@TK2MSFTNGP09.phx.gbl>
<9G**************@TK2MSFTNGXA02.phx.gbl>
Subject: Re: getting client ip in sock-client on server
Date: Fri, 20 Jan 2006 10:47:03 +0530
Lines: 81
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
X-RFC2646: Format=Flowed; Original
Message-ID: <uA*************@tk2msftngp13.phx.gbl>
Newsgroups: microsoft.public.dotnet.languages.csharp
NNTP-Posting-Host: dsl-del-dynamic-130.84.246.61.touchtelindia.net

61.246.84.130
Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msft ngp13.phx.gbl
Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.languages.csharp:37992 4
X-Tomcat-NG: microsoft.public.dotnet.languages.csharp

is there anything in framework 2.0
to get the remote address
""TerryFei"" <v-******@online.microsoft.com> wrote in message
news:9G**************@TK2MSFTNGXA02.phx.gbl...
Hi Ankit,

In this current situation, I suggest you could try to invoke getpeername

/ getsockname using PInvoke mechanism. On a connected socket, getpeername
will give you the remote address and getsockname will give you the local
address for the connection. We could use Socket.Handle Property to get the socket handle and pass it into these API as parameters.

I hope the above inforamtion is helpful for you.If you have any
questions
or concerns, please let me know. Thanks again and have a nice day!

Best Regards,

Terry Fei[MSFT]
Microsoft Community Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Best Regards,

--------------------
From: "Ankit Aneja" <ef*****@newsgroups.nospam>
References: <uq**************@TK2MSFTNGP14.phx.gbl>
<dq**********@sunce.iskon.hr> <Oz**************@TK2MSFTNGP15.phx.gbl>
<e0**************@TK2MSFTNGP10.phx.gbl>
Subject: Re: getting client ip in sock-client on server
Date: Thu, 19 Jan 2006 19:18:12 +0530
Lines: 30
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
X-RFC2646: Format=Flowed; Original
Message-ID: <Ox**************@TK2MSFTNGP09.phx.gbl>
Newsgroups: microsoft.public.dotnet.languages.csharp
NNTP-Posting-Host: dsl-del-dynamic-067.85.246.61.touchtelindia.net
61.246.85.67
Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP09.phx.gbl
Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.languages.csharp:37968 4
X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
No, it won't. I can't find anything in TcpClient documentation (fw 1.1)
class that would reveal client's IP address (but I may be wrong here)

can i get it using framework 2.0
pls help


"Goran Sliskovic" <gs******@yahoo.com> wrote in message
news:e0**************@TK2MSFTNGP10.phx.gbl.. .
>
> "Ankit Aneja" <ef*****@newsgroups.nospam> wrote in message
> news:Oz**************@TK2MSFTNGP15.phx.gbl...
>> will it give ip address of client
>> i want to fetch ip address on server of client which is accepted or
>> connected
> ...
>
> No, it won't. I can't find anything in TcpClient documentation (fw
> 1.1)
> class that would reveal client's IP address (but I may be wrong here)
> .
If
> you can use Socket class, then you can use RemoteEndPoint property.
>
> Regards,
> Goran
>
>


Jan 20 '06 #10

""TerryFei"" <v-******@online.microsoft.com> wrote in message
news:9G**************@TK2MSFTNGXA02.phx.gbl...
Hi Ankit,

In this current situation, I suggest you could try to invoke getpeername /
getsockname using PInvoke mechanism. On a connected socket, getpeername
will give you the remote address and getsockname will give you the local
address for the connection. We could use Socket.Handle Property to get the
socket handle and pass it into these API as parameters.

I hope the above inforamtion is helpful for you.If you have any questions
or concerns, please let me know. Thanks again and have a nice day!


....

The problem is that TcpClient does not expose underlying socket. Socket
TcpClient.Client is protected property (holds underlying socket). I suspect
OP could get this using reflection (I heard this is possible using
reflection, but haven't tried it myself and it is bad practice to do this of
course). Socket has RemoteEndPoint property, so it should not be needed to
PInvoke. Haven't tested it, though. Or maybe I missed the original problem?

Regards,
Goran
Jan 20 '06 #11
can u give me some sample code
how i can get remote ip without changing much of my present code
"Goran Sliskovic" <gs******@yahoo.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...

""TerryFei"" <v-******@online.microsoft.com> wrote in message
news:9G**************@TK2MSFTNGXA02.phx.gbl...
Hi Ankit,

In this current situation, I suggest you could try to invoke getpeername
/
getsockname using PInvoke mechanism. On a connected socket, getpeername
will give you the remote address and getsockname will give you the local
address for the connection. We could use Socket.Handle Property to get
the
socket handle and pass it into these API as parameters.

I hope the above inforamtion is helpful for you.If you have any questions
or concerns, please let me know. Thanks again and have a nice day!


...

The problem is that TcpClient does not expose underlying socket. Socket
TcpClient.Client is protected property (holds underlying socket). I
suspect
OP could get this using reflection (I heard this is possible using
reflection, but haven't tried it myself and it is bad practice to do this
of
course). Socket has RemoteEndPoint property, so it should not be needed to
PInvoke. Haven't tested it, though. Or maybe I missed the original
problem?

Regards,
Goran

Jan 21 '06 #12

"Ankit Aneja" <ef*****@newsgroups.nospam> wrote in message
news:eb**************@TK2MSFTNGP14.phx.gbl...
can u give me some sample code
how i can get remote ip without changing much of my present code

....

Hi,

Here it is:
<CUT>
using System;
using System.Reflection;
using System.Reflection.Emit;

using System.Net;
using System.Net.Sockets;

namespace ConsoleApplication1 {
public class Test {
public static void Main() {
TcpListener tcpListener = new TcpListener(IPAddress.Any, 10000);
tcpListener.Start();
TcpClient client = tcpListener.AcceptTcpClient();
Type tcpClientType = typeof(TcpClient);
//get value of protected TCPClient property Client that holds
socket...
Socket clientSocket =
(Socket)tcpClientType.InvokeMember("Client", BindingFlags.GetProperty |
BindingFlags.NonPublic | BindingFlags.Instance , null, client, null);
//socket RemoteEndpoint is address of connected tcpClinet...
IPEndPoint endPoint = (IPEndPoint) clientSocket.RemoteEndPoint;
string remotAddr = endPoint.Address.ToString();
}
}
}
</CUT>

Please note that such thing is considered bad practice and potentialy
dangerous. No guarantees.

Regards,
Goran

Jan 21 '06 #13
Hi Goran,
Socket has RemoteEndPoint property, so it should not be needed to
PInvoke. Haven't tested it Thanks for your reply! Yes, Socket has RemoteEndPoint property and we could
access relevant address with it in theory. However customer has tried it
and failed. So I suggest use PInvoke to achieve this goal.

Best Regards,

Terry Fei[MSFT]
Microsoft Community Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
From: "Goran Sliskovic" <gs******@yahoo.com>
References: <uq**************@TK2MSFTNGP14.phx.gbl> <dq**********@sunce.iskon.hr> <Oz**************@TK2MSFTNGP15.phx.gbl>
<e0**************@TK2MSFTNGP10.phx.gbl>
<Ox**************@TK2MSFTNGP09.phx.gbl>
<9G**************@TK2MSFTNGXA02.phx.gbl>Subject: Re: getting client ip in sock-client on server
Date: Fri, 20 Jan 2006 14:03:53 +0100
Lines: 27
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1506
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1506
Message-ID: <#q*************@tk2msftngp13.phx.gbl>
Newsgroups: microsoft.public.dotnet.languages.csharp
NNTP-Posting-Host: 194-152-209-27.adsl.net.t-com.hr 194.152.209.27
Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msft ngp13.phx.gbl
Xref: TK2MSFTNGXA02.phx.gbl microsoft.public.dotnet.languages.csharp:379994
X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
""TerryFei"" <v-******@online.microsoft.com> wrote in message
news:9G**************@TK2MSFTNGXA02.phx.gbl...
Hi Ankit,

In this current situation, I suggest you could try to invoke getpeername
/ getsockname using PInvoke mechanism. On a connected socket, getpeername
will give you the remote address and getsockname will give you the local
address for the connection. We could use Socket.Handle Property to get the socket handle and pass it into these API as parameters.

I hope the above inforamtion is helpful for you.If you have any questions
or concerns, please let me know. Thanks again and have a nice day!


...

The problem is that TcpClient does not expose underlying socket. Socket
TcpClient.Client is protected property (holds underlying socket). I suspect
OP could get this using reflection (I heard this is possible using
reflection, but haven't tried it myself and it is bad practice to do this

ofcourse). Socket has RemoteEndPoint property, so it should not be needed to
PInvoke. Haven't tested it, though. Or maybe I missed the original problem?

Regards,
Goran


Jan 23 '06 #14

""TerryFei"" <v-******@online.microsoft.com> wrote in message
news:3n****************@TK2MSFTNGXA02.phx.gbl...
Hi Goran,
Socket has RemoteEndPoint property, so it should not be needed to
PInvoke. Haven't tested it
Thanks for your reply! Yes, Socket has RemoteEndPoint property and we

could access relevant address with it in theory. However customer has tried it
and failed. So I suggest use PInvoke to achieve this goal.

....

Hi,

I posted example with tcpclient/remoteendpoint that works (no my lan),
framework 1.1. Though I can guess there may be problems in non-trivial
network setups (NAT for example).

Regards,
Goran
Jan 23 '06 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: MJL | last post by:
This is a mysql/php question (but a little more on the mysql side.) The two are so closely related these days, I thought it would be ok to ask here. I installed on my Suse Linux system mysql 4.0...
0
by: Oliver Etzel - GoodnGo.COM | last post by:
Hello all, after Installing mysql I started the mysql daemon.. The I tried to log in to my mysql database and got the message could not find mysql.sock in /tmp. In the mysql-configuration...
0
by: Oliver Etzel - GoodnGo.COM | last post by:
Hello all, after Installing mysql I started the mysql daemon.. The I tried to log in to my mysql database and got the message could not find mysql.sock in /tmp. In the mysql-configuration...
0
by: Oliver Etzel - GoodnGo.COM | last post by:
Hello all, after Installing mysql I started the mysql daemon.. Then I tried to log in to my mysql database and got the message could not find mysql.sock in /tmp. In the mysql-configuration...
1
by: JW | last post by:
Hi all, I was fine running mysql, and for some reason, after the most recent reboot of my machine, I get the following error and I try the following subsequent commands to try to figure things...
0
by: DevBoy | last post by:
I installed the base MySQL 4.0 with Suse Linux and I try and start it and I get anb issue with the fact that mysql.sock file does not exist in /etc..../mysql/mysql.sock I created a file and made...
5
by: OZ | last post by:
the serproxy claim itself a multi-thread proxy thing. I have sent email to write the original writer and there is no replay after 3 weeks. my configuration and setting are good. ...
1
by: vabh | last post by:
Help from there, i want the IP Address of all computers which are connected in LAN with me. Its really urgent for me. I using one kind of coding which returns me IP Address of only one computer, but...
2
by: Roopesh | last post by:
Hi, I am using poplib's retr() to fetch mails from my gmail account. It works fine, in some cases it gets stuck inside the retr() method and does not come out. From the logs I could find that...
185
by: jacob navia | last post by:
Hi We are rewriting the libc for the 64 bit version of lcc-win and we have added a new field in the FILE structure: char *FileName; fopen() will save the file name and an accessor function will...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.