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

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 11692
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
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
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
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
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
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
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
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
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
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: ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.