* Re: test for network connection location
[not found] <494555b1-e47b-4208-abf5-ec446e449082@f63g2000hsf.googlegroups.com>
@ 2008-04-14 20:30 ` Rupert Swarbrick
2008-04-15 8:30 ` Sébastien Vauban
1 sibling, 0 replies; 2+ messages in thread
From: Rupert Swarbrick @ 2008-04-14 20:30 UTC (permalink / raw)
To: help-gnu-emacs
Alan <wehmann@fnal.gov> writes:
> I haven't been able to think of a way to put a test in my .vm file
> that would distinguish between when my laptop is connected to the
> internet while at home, versus being connected while at work. In both
> cases I am interested in fetching mail from the IMAP server at work,
> but I'd like to configure three variables in .vm somewhat differently--
> depending on how the laptop is connected.
>
> While at home I am using wireless, via a modem with the brand name
> 2wire, with a DSL connection supplied by AT&T (formerly SBC). At work
> I usually connect via an Ethernet cable, but would like to keep the
> option of going wireless. I'd like to set up an environmental
> variable or some other test that could distinguish between these two
> connections, but haven't come up with anything yet. Also, I haven't
> yet invented a good search string to use, to find an existing post
> that suggests how to create such a test.
Hi there,
You haven't said what OS you're using, but I think I might have an
idea if you're using linux (which, frankly, is all that I know
about).
Why not use a shell command? For example, this (horrible) elisp
command checks whether the ESSID of the wireless I'm connected to is
PoorStudents (the one at home!)
(defun at-home-p ()
(string=
(shell-command-to-string
"/sbin/iwconfig wlan0 | grep ESSID | awk -F '\"' '{print $2}'")
"PoorStudents
"))
The slightly lame embedded newline is probably avoidable, but I wrote
this in a hurry...
Rupert
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: test for network connection location
[not found] <494555b1-e47b-4208-abf5-ec446e449082@f63g2000hsf.googlegroups.com>
2008-04-14 20:30 ` test for network connection location Rupert Swarbrick
@ 2008-04-15 8:30 ` Sébastien Vauban
1 sibling, 0 replies; 2+ messages in thread
From: Sébastien Vauban @ 2008-04-15 8:30 UTC (permalink / raw)
To: help-gnu-emacs
Alan,
> I haven't been able to think of a way to put a test in my .vm
> file that would distinguish between when my laptop is
> connected to the internet while at home, versus being
> connected while at work. In both cases I am interested in
> fetching mail from the IMAP server at work, but I'd like to
> configure three variables in .vm somewhat differently--
> depending on how the laptop is connected.
This works for me, with Gnus.
I am testing the IP address (both under Windows *and* Linux, as
I'm using both), which is sufficient for my need:
--8<---------------cut here---------------start------------->8---
;; managing multiple SMTP servers
(defun my-get-domain-name ()
"Determine the current domain name."
(interactive)
(save-excursion
(let ((my-domain-name)
(my-ip-address))
(if running-ms-windows
(progn
(setq my-domain-name
(progn (ipconfig)
(set-buffer "*Ipconfig*")
(goto-char (point-min))
(sleep-for 2)
(if (re-search-forward
"Connection-specific DNS Suffix.*: \\([a-zA-Z0-9].*\\)"
nil t)
(match-string 1)
"*unknown*")))
(kill-buffer "*Ipconfig*"))
(progn
(let ((my-ifconfig (shell-command-to-string "ifconfig -a")))
(when (string-match "inet addr:\\([0-9]+.[0-9]+.[0-9]+.[0-9]+ \\)"
my-ifconfig)
(setq my-ip-address (match-string 1 my-ifconfig))
(message my-ip-address)
(setq my-domain-name
(cond
((string-match "^192.168." my-ip-address)
"domain1.fr")
((string-match "^10.10.1" my-ip-address)
"domain2.com")
((string-match "^169." my-ip-address)
"domain3.net")
(t
"*unknown*")))))))
my-domain-name)))
(defun my-change-smtp-server ()
"Change the SMTP server according to the current domain name."
(save-excursion
(let* ((domain (my-get-domain-name)))
(setq smtpmail-smtp-server
;; where am I?
(cond ((string= "domain1.fr" domain)
"out.domain1.fr")
((string= "domain2.com" domain)
"mail.domain2.com")
((string= "domain3.net" domain)
"localhost")
(t
(error (concat "Don't know which mail server to use for `"
domain "' domain")))))
(message "Domain name is `%s', setting `smtpmail-smtp-server' to `%s'"
domain smtpmail-smtp-server))))
(add-hook 'message-send-hook 'my-change-smtp-server)
--8<---------------cut here---------------end--------------->8---
Any comment is welcome!
Best regards,
Seb
--
Sébastien Vauban
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2008-04-15 8:30 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <494555b1-e47b-4208-abf5-ec446e449082@f63g2000hsf.googlegroups.com>
2008-04-14 20:30 ` test for network connection location Rupert Swarbrick
2008-04-15 8:30 ` Sébastien Vauban
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.