473,394 Members | 1,722 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,394 software developers and data experts.

How to get the remote port number in asp.net

I know that I can get the SERVER port number like this:

HttpContext.Current.Request.ServerVariables["SERVER_PORT"]

My question is how do I get the remote CLIENT port number?

Thanks
Derek

Oct 18 '06 #1
9 13520
For communication to work, the client and server would have to use the same
port. So, it's safe to say the the client port and the server port should be
the same. However, this may not be the case. I'm sure someone would correct
me if I am wrong.

<xp******@gmail.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
>I know that I can get the SERVER port number like this:

HttpContext.Current.Request.ServerVariables["SERVER_PORT"]

My question is how do I get the remote CLIENT port number?

Thanks
Derek
Oct 18 '06 #2

HttpContext.Current.Request.UserHostAddress
or Request.UserHostAddress if you're working inline code.

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
<xp******@gmail.comwrote in message news:11**********************@b28g2000cwb.googlegr oups.com...
>I know that I can get the SERVER port number like this:

HttpContext.Current.Request.ServerVariables["SERVER_PORT"]

My question is how do I get the remote CLIENT port number?

Thanks
Derek

Oct 18 '06 #3
Please ignore that reply.

I thought you were asking for the user's IP address, not the port.

re:
My question is how do I get the remote CLIENT port number?
There's no such animal.
The client will make the request on whatever port the server is configured for.


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"Juan T. Llibre" <no***********@nowhere.comwrote in message
news:OL**************@TK2MSFTNGP05.phx.gbl...
>
HttpContext.Current.Request.UserHostAddress
or Request.UserHostAddress if you're working inline code.

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
<xp******@gmail.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
>>I know that I can get the SERVER port number like this:

HttpContext.Current.Request.ServerVariables["SERVER_PORT"]

My question is how do I get the remote CLIENT port number?

Thanks
Derek


Oct 18 '06 #4
<xp******@gmail.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
>I know that I can get the SERVER port number like this:

HttpContext.Current.Request.ServerVariables["SERVER_PORT"]

My question is how do I get the remote CLIENT port number?
I'm not sure which port you're referring to here...???
Oct 18 '06 #5
I'm referring to the client TCP/IP port number that the http response
will be sent on. If I go onto the web server and use a utility like
netstat I can see both sides of the connection -- usually, the server
port number will be 80 or 443 and the client will be a high port
number. I'm wondering if there is a way to access this port number via
code.

On Oct 18, 10:37 am, "Mark Rae" <m...@markNOSPAMrae.comwrote:
<xparr...@gmail.comwrote in messagenews:11**********************@b28g2000cwb.g ooglegroups.com...
I know that I can get the SERVER port number like this:
HttpContext.Current.Request.ServerVariables["SERVER_PORT"]
My question is how do I get the remote CLIENT port number?I'm not sure which port you're referring to here...???
Oct 18 '06 #6
I think that high port number you may be seeing is a result of NAT that is
usually done by routers. You will not be able to get this port number since
this is not seen from the outside world. So, in the end, the client and
server will communicate using the same port (80 or 443); but NAT makes it
seem like its using another port.

<xp******@gmail.comwrote in message
news:11********************@i3g2000cwc.googlegroup s.com...
I'm referring to the client TCP/IP port number that the http response
will be sent on. If I go onto the web server and use a utility like
netstat I can see both sides of the connection -- usually, the server
port number will be 80 or 443 and the client will be a high port
number. I'm wondering if there is a way to access this port number via
code.

On Oct 18, 10:37 am, "Mark Rae" <m...@markNOSPAMrae.comwrote:
><xparr...@gmail.comwrote in
messagenews:11**********************@b28g2000cwb. googlegroups.com...
>I know that I can get the SERVER port number like this:
HttpContext.Current.Request.ServerVariables["SERVER_PORT"]
My question is how do I get the remote CLIENT port number?I'm not sure
which port you're referring to here...???
Oct 18 '06 #7
re:
I'm referring to the client TCP/IP port number that the http response will be sent on.
I'm wondering if there is a way to access this port number via code.
I think that's a random number above 1024.
It's picked from the pool of available ports (so as to avoid picking one that currently in use).

There's absolutely no programming need which could be
filled by accessing it before the packets are actually sent.


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
<xp******@gmail.comwrote in message news:11********************@i3g2000cwc.googlegroup s.com...
I'm referring to the client TCP/IP port number that the http response
will be sent on. If I go onto the web server and use a utility like
netstat I can see both sides of the connection -- usually, the server
port number will be 80 or 443 and the client will be a high port
number. I'm wondering if there is a way to access this port number via
code.

On Oct 18, 10:37 am, "Mark Rae" <m...@markNOSPAMrae.comwrote:
><xparr...@gmail.comwrote in
messagenews:11**********************@b28g2000cwb. googlegroups.com...
>I know that I can get the SERVER port number like this:
HttpContext.Current.Request.ServerVariables["SERVER_PORT"]
My question is how do I get the remote CLIENT port number?I'm not sure which port you're
referring to here...???

Oct 18 '06 #8
<xp******@gmail.comwrote in message
news:11********************@i3g2000cwc.googlegroup s.com...
I'm referring to the client TCP/IP port number that the http response
will be sent on. If I go onto the web server and use a utility like
netstat I can see both sides of the connection -- usually, the server
port number will be 80 or 443 and the client will be a high port
number. I'm wondering if there is a way to access this port number via
code.
Oh right...

Hmm - IIRC this is an entirely random port picked from a pool of available
ports between something like 1024 and 65536, but I don't think there's any
way of finding out its number through the standard HttpRequest /
HttpResponse connectivity.

AAMOI, what possible use could this number be to you...?
Oct 18 '06 #9
Hmm - IIRC this is an entirely randomportpicked from a pool of available
ports between something like 1024 and 65536, but I don't think there's any
way of finding out its number through the standard HttpRequest /
HttpResponse connectivity.

AAMOI, what possible use could this number be to you...?
To answer your question -- The remote port can be used to determine the
machine that a request was originally routed from behind a NAT enabled
router. When NAT is used, all requests behind a router appear to come
from the same IP address. The only thing that differs is the port
number. NAT uses the port number to route the request back to the
proper machine on the private subnet.

In response to previous posts, the request would rarely be sent back to
the client on port 80 or 443. These ports would only be open on the
server machine. In fact, some personal firewalls would block these
ports entirely on a client PC. Usually the client initiates the
request and chooses a random high number port for its side of the
socket and connects to a known port on the server (80,443). When the
response is returned from the server it it sent back via the high
numbered client port for which it originated. You can observe this by
running "netstat -N" from the command line on a web server. It will
show all open client connections to the web server. You will see the
high numbered remote ports with the client address and standard ports
80 and 443 on the server side. Hope this clears up the port
confusion.
>From the responses so far, it sounds like there is no easy way to
access this information via ASP.net.

Oct 19 '06 #10

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

Similar topics

3
by: Fredric Ragnar | last post by:
Hi, I am making a prototype system with Remoting in the bottom of the system. An XML Web Service is using the remote object on an IIS to present data. I am using a TcpChannel for communicating...
9
by: RvGrah | last post by:
After much hair-pulling, I've finally found the answer to a problem that many are fighting with, difficulty connecting from Sql 2005 Server Management or VS2005 to a remote Sql Server running Sql...
4
by: tommaso.gastaldi | last post by:
If one does not configure a virtual dir as an IIS application, he/she receives the common error: ---------------------------------------- Server Error in '/' Application. .... This error can be...
3
by: nandan | last post by:
Yes. My client has a proxy server. That much i know. In my application I make two kinds of calls that are affected by the proxy server I finally got the webservice call working. But my...
10
by: mairhtin o'feannag | last post by:
Hello, I'm having problems connecting to my new v9 db box. The pertinent information is below: DB2_db2inst1 60000/tcp DB2_db2inst1_1 60001/tcp DB2_db2inst1_2 60002/tcp DB2_db2inst1_END...
1
by: koole | last post by:
HI, This is the present situation. 1.I have Db2 9.1 installed on 1 AIX machines(server).I have database created and everything is runniing. 2.I have another server with db2 9.1 and I want...
8
by: John | last post by:
Hi We had an sbs 2003 with isa 2000 server. We wre able to access a remote sql server (hosted at our web host) just fine. We replaced the server with a new sbs 2003 r2 with isa 2004 server and...
1
Shashi Sadasivan
by: Shashi Sadasivan | last post by:
Hi, After some search around, trying to get my SQL Management studio (running on Vista) to connect to a remote SQL server instance, i finally nailed it. Your management studio will refuse to...
1
by: malooga | last post by:
Hello, I'm having a problem connecting to DB2 on a remote iSeries host from a Linux server, both of which reside on my company's internal network. I'm using the IBM Linux Client V9.1. When I try...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.