How to create a webpage that can be accessed by other IPs (Python wsgiref.simple_server)
How to config that host apart from localhost so that it can be accessed by other computers as well?
Is it doable?
from wsgiref.simple_server import make_server
def hello_world(environ, start_response):
status = '200 ok'
headers = [('Content-type','text/plain')]
start_response(status, headers)
return ['Hello World']
def run():
httpd = make_server(localhost, 8000, hello_world)
print 'Serving on port 80...'
httpd.serve_forever()
if __name__ == '__main__':
run()
python
add a comment |
How to config that host apart from localhost so that it can be accessed by other computers as well?
Is it doable?
from wsgiref.simple_server import make_server
def hello_world(environ, start_response):
status = '200 ok'
headers = [('Content-type','text/plain')]
start_response(status, headers)
return ['Hello World']
def run():
httpd = make_server(localhost, 8000, hello_world)
print 'Serving on port 80...'
httpd.serve_forever()
if __name__ == '__main__':
run()
python
code formatting some, fluff waya
– pirho
Nov 21 '18 at 16:15
you can try python -m SimpleHTTPServer in command line.
– Nimish Bansal
Nov 21 '18 at 16:18
add a comment |
How to config that host apart from localhost so that it can be accessed by other computers as well?
Is it doable?
from wsgiref.simple_server import make_server
def hello_world(environ, start_response):
status = '200 ok'
headers = [('Content-type','text/plain')]
start_response(status, headers)
return ['Hello World']
def run():
httpd = make_server(localhost, 8000, hello_world)
print 'Serving on port 80...'
httpd.serve_forever()
if __name__ == '__main__':
run()
python
How to config that host apart from localhost so that it can be accessed by other computers as well?
Is it doable?
from wsgiref.simple_server import make_server
def hello_world(environ, start_response):
status = '200 ok'
headers = [('Content-type','text/plain')]
start_response(status, headers)
return ['Hello World']
def run():
httpd = make_server(localhost, 8000, hello_world)
print 'Serving on port 80...'
httpd.serve_forever()
if __name__ == '__main__':
run()
python
python
edited Nov 21 '18 at 16:15
pirho
5,021111832
5,021111832
asked Nov 21 '18 at 15:34
IanIan
11
11
code formatting some, fluff waya
– pirho
Nov 21 '18 at 16:15
you can try python -m SimpleHTTPServer in command line.
– Nimish Bansal
Nov 21 '18 at 16:18
add a comment |
code formatting some, fluff waya
– pirho
Nov 21 '18 at 16:15
you can try python -m SimpleHTTPServer in command line.
– Nimish Bansal
Nov 21 '18 at 16:18
code formatting some, fluff waya
– pirho
Nov 21 '18 at 16:15
code formatting some, fluff waya
– pirho
Nov 21 '18 at 16:15
you can try python -m SimpleHTTPServer in command line.
– Nimish Bansal
Nov 21 '18 at 16:18
you can try python -m SimpleHTTPServer in command line.
– Nimish Bansal
Nov 21 '18 at 16:18
add a comment |
1 Answer
1
active
oldest
votes
Simply pass an empty string as the hostname, and it will bind to your public network interface:
httpd = make_server('', 8000, hello_world)
If you're using Windows, you can confirm this with netstat
as follows. When I pass 'localhost'
as the first argument, it binds to 127.0.0.1
:
PS C:Userscody> netstat -a -n | findstr LISTENING | findstr :8000
TCP 127.0.0.1:8000 0.0.0.0:0 LISTENING
When I pass ''
, it binds to 0.0.0.0
, which essentially means "all interfaces":
PS C:Userscody> netstat -a -n | findstr LISTENING | findstr :8000
TCP 0.0.0.0:8000 0.0.0.0:0 LISTENING
Now even if you're successfully listening on a public interface, if you have a firewall running you may have to disable it before anything external will be able to connect.
Hi, if I use an empty string, does it mean that I'm using my local host address? Then it still can't be accessed by other computers?
– Ian
Nov 22 '18 at 14:35
No,''
will bind to0.0.0.0
, see my edited answer.
– cody
Nov 22 '18 at 14:49
Thank you Cody!! Now I understand better.
– Ian
Nov 24 '18 at 15:26
Great, so did this solve your problem? If so, please mark the answer as accepted.
– cody
Nov 24 '18 at 16:19
Yes, thank you Cody. Sorry I am new to stack overflow. I didn't know I should mark it accepted. Thanks for reminding.
– Ian
Nov 25 '18 at 13:18
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53415497%2fhow-to-create-a-webpage-that-can-be-accessed-by-other-ips-python-wsgiref-simple%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Simply pass an empty string as the hostname, and it will bind to your public network interface:
httpd = make_server('', 8000, hello_world)
If you're using Windows, you can confirm this with netstat
as follows. When I pass 'localhost'
as the first argument, it binds to 127.0.0.1
:
PS C:Userscody> netstat -a -n | findstr LISTENING | findstr :8000
TCP 127.0.0.1:8000 0.0.0.0:0 LISTENING
When I pass ''
, it binds to 0.0.0.0
, which essentially means "all interfaces":
PS C:Userscody> netstat -a -n | findstr LISTENING | findstr :8000
TCP 0.0.0.0:8000 0.0.0.0:0 LISTENING
Now even if you're successfully listening on a public interface, if you have a firewall running you may have to disable it before anything external will be able to connect.
Hi, if I use an empty string, does it mean that I'm using my local host address? Then it still can't be accessed by other computers?
– Ian
Nov 22 '18 at 14:35
No,''
will bind to0.0.0.0
, see my edited answer.
– cody
Nov 22 '18 at 14:49
Thank you Cody!! Now I understand better.
– Ian
Nov 24 '18 at 15:26
Great, so did this solve your problem? If so, please mark the answer as accepted.
– cody
Nov 24 '18 at 16:19
Yes, thank you Cody. Sorry I am new to stack overflow. I didn't know I should mark it accepted. Thanks for reminding.
– Ian
Nov 25 '18 at 13:18
add a comment |
Simply pass an empty string as the hostname, and it will bind to your public network interface:
httpd = make_server('', 8000, hello_world)
If you're using Windows, you can confirm this with netstat
as follows. When I pass 'localhost'
as the first argument, it binds to 127.0.0.1
:
PS C:Userscody> netstat -a -n | findstr LISTENING | findstr :8000
TCP 127.0.0.1:8000 0.0.0.0:0 LISTENING
When I pass ''
, it binds to 0.0.0.0
, which essentially means "all interfaces":
PS C:Userscody> netstat -a -n | findstr LISTENING | findstr :8000
TCP 0.0.0.0:8000 0.0.0.0:0 LISTENING
Now even if you're successfully listening on a public interface, if you have a firewall running you may have to disable it before anything external will be able to connect.
Hi, if I use an empty string, does it mean that I'm using my local host address? Then it still can't be accessed by other computers?
– Ian
Nov 22 '18 at 14:35
No,''
will bind to0.0.0.0
, see my edited answer.
– cody
Nov 22 '18 at 14:49
Thank you Cody!! Now I understand better.
– Ian
Nov 24 '18 at 15:26
Great, so did this solve your problem? If so, please mark the answer as accepted.
– cody
Nov 24 '18 at 16:19
Yes, thank you Cody. Sorry I am new to stack overflow. I didn't know I should mark it accepted. Thanks for reminding.
– Ian
Nov 25 '18 at 13:18
add a comment |
Simply pass an empty string as the hostname, and it will bind to your public network interface:
httpd = make_server('', 8000, hello_world)
If you're using Windows, you can confirm this with netstat
as follows. When I pass 'localhost'
as the first argument, it binds to 127.0.0.1
:
PS C:Userscody> netstat -a -n | findstr LISTENING | findstr :8000
TCP 127.0.0.1:8000 0.0.0.0:0 LISTENING
When I pass ''
, it binds to 0.0.0.0
, which essentially means "all interfaces":
PS C:Userscody> netstat -a -n | findstr LISTENING | findstr :8000
TCP 0.0.0.0:8000 0.0.0.0:0 LISTENING
Now even if you're successfully listening on a public interface, if you have a firewall running you may have to disable it before anything external will be able to connect.
Simply pass an empty string as the hostname, and it will bind to your public network interface:
httpd = make_server('', 8000, hello_world)
If you're using Windows, you can confirm this with netstat
as follows. When I pass 'localhost'
as the first argument, it binds to 127.0.0.1
:
PS C:Userscody> netstat -a -n | findstr LISTENING | findstr :8000
TCP 127.0.0.1:8000 0.0.0.0:0 LISTENING
When I pass ''
, it binds to 0.0.0.0
, which essentially means "all interfaces":
PS C:Userscody> netstat -a -n | findstr LISTENING | findstr :8000
TCP 0.0.0.0:8000 0.0.0.0:0 LISTENING
Now even if you're successfully listening on a public interface, if you have a firewall running you may have to disable it before anything external will be able to connect.
edited Nov 22 '18 at 14:48
answered Nov 21 '18 at 16:18
codycody
7,11631126
7,11631126
Hi, if I use an empty string, does it mean that I'm using my local host address? Then it still can't be accessed by other computers?
– Ian
Nov 22 '18 at 14:35
No,''
will bind to0.0.0.0
, see my edited answer.
– cody
Nov 22 '18 at 14:49
Thank you Cody!! Now I understand better.
– Ian
Nov 24 '18 at 15:26
Great, so did this solve your problem? If so, please mark the answer as accepted.
– cody
Nov 24 '18 at 16:19
Yes, thank you Cody. Sorry I am new to stack overflow. I didn't know I should mark it accepted. Thanks for reminding.
– Ian
Nov 25 '18 at 13:18
add a comment |
Hi, if I use an empty string, does it mean that I'm using my local host address? Then it still can't be accessed by other computers?
– Ian
Nov 22 '18 at 14:35
No,''
will bind to0.0.0.0
, see my edited answer.
– cody
Nov 22 '18 at 14:49
Thank you Cody!! Now I understand better.
– Ian
Nov 24 '18 at 15:26
Great, so did this solve your problem? If so, please mark the answer as accepted.
– cody
Nov 24 '18 at 16:19
Yes, thank you Cody. Sorry I am new to stack overflow. I didn't know I should mark it accepted. Thanks for reminding.
– Ian
Nov 25 '18 at 13:18
Hi, if I use an empty string, does it mean that I'm using my local host address? Then it still can't be accessed by other computers?
– Ian
Nov 22 '18 at 14:35
Hi, if I use an empty string, does it mean that I'm using my local host address? Then it still can't be accessed by other computers?
– Ian
Nov 22 '18 at 14:35
No,
''
will bind to 0.0.0.0
, see my edited answer.– cody
Nov 22 '18 at 14:49
No,
''
will bind to 0.0.0.0
, see my edited answer.– cody
Nov 22 '18 at 14:49
Thank you Cody!! Now I understand better.
– Ian
Nov 24 '18 at 15:26
Thank you Cody!! Now I understand better.
– Ian
Nov 24 '18 at 15:26
Great, so did this solve your problem? If so, please mark the answer as accepted.
– cody
Nov 24 '18 at 16:19
Great, so did this solve your problem? If so, please mark the answer as accepted.
– cody
Nov 24 '18 at 16:19
Yes, thank you Cody. Sorry I am new to stack overflow. I didn't know I should mark it accepted. Thanks for reminding.
– Ian
Nov 25 '18 at 13:18
Yes, thank you Cody. Sorry I am new to stack overflow. I didn't know I should mark it accepted. Thanks for reminding.
– Ian
Nov 25 '18 at 13:18
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53415497%2fhow-to-create-a-webpage-that-can-be-accessed-by-other-ips-python-wsgiref-simple%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
code formatting some, fluff waya
– pirho
Nov 21 '18 at 16:15
you can try python -m SimpleHTTPServer in command line.
– Nimish Bansal
Nov 21 '18 at 16:18