473,480 Members | 1,820 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How set the source IP adress

Hi,

how to set source ip-address when do __socket.connect((host, port))
on a machine that have a several ip-adresses?

many thanks for advice.

__socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
__socket.connect((host, port))
--
Maksim Kasimov
Oct 27 '06 #1
3 11717
Maksim Kasimov wrote:
Hi,

how to set source ip-address when do __socket.connect((host, port))
on a machine that have a several ip-adresses?

many thanks for advice.

__socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
__socket.connect((host, port))

sock.connect ( ('11.22.33.44', 9999) )

i.e. just put the ip address as string parameter into the connect address tuple
(where you wrote: host)

--Irmen
Oct 27 '06 #2
On 2006-10-27, Irmen de Jong <ir**********@xs4all.nlwrote:
>how to set source ip-address when do __socket.connect((host, port))
on a machine that have a several ip-adresses?

__socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
__socket.connect((host, port))

sock.connect ( ('11.22.33.44', 9999) )

i.e. just put the ip address as string parameter into the
connect address tuple (where you wrote: host)
Um, no. That controls the _destination_ IP address, not the
source. If you want to control the source IP addresss you can
bind it to a local interface's IP address before doing the
connect() call.

sock.bind(('10.0.0.99',-1)) # -1: don't care about source port number
sock.connect((host,port))

That will make sure that 10.0.0.99 is used as the source IP
address. Of course you have to have an interface with that
address.

--
Grant Edwards grante Yow! I'm a nuclear
at submarine under the
visi.com polar ice cap and I need
a Kleenex!
Oct 27 '06 #3
On 2006-10-27, Grant Edwards <gr****@visi.comwrote:
On 2006-10-27, Irmen de Jong <ir**********@xs4all.nlwrote:
>>how to set source ip-address when do __socket.connect((host, port))
on a machine that have a several ip-adresses?

__socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
__socket.connect((host, port))

sock.connect ( ('11.22.33.44', 9999) )

i.e. just put the ip address as string parameter into the
connect address tuple (where you wrote: host)

Um, no. That controls the _destination_ IP address, not the
source. If you want to control the source IP addresss you can
bind it to a local interface's IP address before doing the
connect() call.

sock.bind(('10.0.0.99',-1)) # -1: don't care about source port number
sock.connect((host,port))
Doh! That should have been 0 not -1.

--
Grant Edwards grante Yow! Do I hear th'
at SPINNING of various
visi.com WHIRRING, ROUND, and WARM
WHIRLOMATICS?!
Oct 27 '06 #4

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

Similar topics

6
2243
by: RosalieM | last post by:
How can i know the nic adress from an incoming socket ? I can easily know the ip adress and port number but how do i have some information about arp level ? Thanks
0
1411
by: Jarod_24 | last post by:
I got a function that return the url of a image, the problem is that the image control on the .aspx page automaticaly adds the adress of itself to the adress Example: The page...
3
1598
by: Jarod_24 | last post by:
I got a function that return the url of a image, the problem is that the image control on the .aspx page automaticaly adds the adress of itself to the adress Example: The page...
0
1037
by: PawelR | last post by:
Hello group, How read from xml source (url adress) to DataTable if I don't have xmlShema? Or how automatic generate xsd document for xml from url adress? BR. PawelR
11
3419
by: mwebel | last post by:
Hi, i had this problem before (posted here and solved it then) now i have the same problem but more complicated and general... basically i want to store the adress of a istream in a char* among...
1
2126
by: Simon | last post by:
Dear reader, By printing an e-mail adress field (hyperlink field) it will be shown as: "xxxx@yyyy.nn#Mailto:xxxx@yyyy.nn#"
3
3637
Sagittarius
by: Sagittarius | last post by:
Hi there. I have a problem concerning an UDP socket in C++ (Winsock). The next paragraphs is merely to explain the system I am working on. If U want to skip it, I have marked the question in...
2
1361
by: hpber | last post by:
Hello, is there a way to retrieve the name of the user who is logged on on a foreign Win Xp machine by giving the ip adress with c/c++ ? A list of necessary function or source code would be...
3
4075
by: Slawomir | last post by:
Hello. Simple question about webforms: How to hide true address of website ? To this day a used "Server.Transfer()" to redirect to another page. In sql server I have a table with data like this: ...
0
7033
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
7027
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,...
1
6726
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
4763
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4468
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2987
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2974
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
557
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
170
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.