Click to See Complete Forum and Search --> : Is complicated CLI emailing able to be made Simple?
Sepero
08-12-2003, 01:54 AM
Ok, here's the deal. I have a computer set up. Whenever this computer dials in to the internet, I want a script to send me an email letting me know it's IP. I then plan to use that to SSH into it.
That is ALL I need from the emailer, but exim has a freaking 100+ page manual! Is there anything I can set up in an hour or less? :(
mdwatts
08-12-2003, 08:46 AM
You could save this source as 'showip'
#include <stdio.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string.h>
void list_all();
void display_iface(char *name);
int fd;
int main(int argc, char *argv[])
{
fd = socket(PF_INET,SOCK_STREAM,0);
if (fd == -1) {
perror("socket() failed");
return 3;
}
if (argc == 1) {
list_all();
return 0;
}
display_iface(argv[1]);
return 0;
}
void display_iface(char *name)
{
struct sockaddr *sa;
struct sockaddr_in *sin;
struct ifreq ifr;
/* Copy the interface name into the buffer */
strncpy(ifr.ifr_name,name,IFNAMSIZ);
if (ioctl(fd,SIOCGIFADDR,&ifr) == -1) {
perror("ioctl failed");
return;
}
/* Now the buffer will contain the information we requested */
printf(ifr.ifr_name);
sa = (struct sockaddr *)&(ifr.ifr_addr);
if (sa->sa_family == AF_INET) {
sin = (struct sockaddr_in*) sa;
printf(": %s\n",inet_ntoa(sin->sin_addr));
} else {
printf(": Unknown Address Family (%d)\n",sa->sa_family);
}
}
void list_all()
{
struct sockaddr *sa;
struct sockaddr_in *sin;
struct ifreq iflist[10];
struct ifconf ifc;
int i;
/* We will list up to 10 interfaces,
* (if you have access to a machine with any more than that,
* you should already know all of this )
*/
ifc.ifc_len = sizeof(struct ifreq) * 10;
ifc.ifc_req = iflist;
if (ioctl(fd,SIOCGIFCONF,&ifc) == -1) {
perror("ioctl failed");
return;
}
for (i = 0; i < ifc.ifc_len/sizeof(struct ifreq); i++) {
printf(iflist[i].ifr_name);
sa = (struct sockaddr *)&(iflist[i].ifr_addr);
if (sa->sa_family == AF_INET) {
sin = (struct sockaddr_in*) sa;
printf(": %s\n",inet_ntoa(sin->sin_addr));
} else {
printf(": Unknown Address Family (%d)\n",sa->sa_family);
}
}
return;
}
and compile using
gcc -o showip.o showip.c
change it to executable, move it to somewhere in your users PATH and then write a script to execute the scipt, pipe the results to a text file and then mail the text file.
showip > text.file
mail "email address" < text.file
(whatever the correct mail command syntax is ??)
ph34r
08-12-2003, 09:06 AM
Why not just set up a dyndns.org account and one of their clients to update your dns entry on connect?
Sepero
08-12-2003, 10:35 AM
!OMG mdwatts!! Did you write that just for me!?! That's so cool!! Can I license it under GPL for ya? :p
I feel kinda bad now, though. The reason is, because the "mail email@ddress" is what I'm having a problem with. 'mail' has to go through my MTA(exim) to send out that email, and exim is my real problem.
I haven't even got to figuring out the IP yet. Ha! But when I do, then I may just need that code. :D
To ph34r:
I don't know anything about dyndns, so thanks for the link. I'll check it out.
If anybody else can think of something good, please post...
(What are you still reading for?? I said post! Hit that "reply" button. Do it already! heheh)
otbibb
08-12-2003, 11:41 AM
How do you normally send mail from this machine? I connect through my school's smtp server to actually send mail, so I don't have sendmail or exim configured to route mail out of my computer. What I do (using Mutt and slrn) is to configure a little program called ssmtp to push mail through to my school's relay server. It has a short config file, and is very easy to figure out. Here is my config file for your reference. You might need to configure it to "rewrite" your headers to be correct, though if it's just going to you it might not matter too much. I don't use sSMTP's rewrite feature because Mutt and slrn create all the right headers for me.
I hope this helps.
bryan@whirlwind:/usr/local/etc/ssmtp$ cat ssmtp.conf
#
# /etc/ssmtp.conf -- a config file for sSMTP sendmail.
#
# The person who gets all mail for userids < 1000
root=bryan
# The example will fit if you are in domain.com and you mailhub is so named.
mailhub=relay.furman.edu
# The full hostname
Sepero
08-12-2003, 12:15 PM
OMG!! Awsome post, otbibb! I just read it's description in aptitude and think this is exactly what I was looking for!!
This has probably been the biggest challenge I have faced with GNU/Linux yet. I mean, exim may be awsome for servers. But for me, it's like trying to learn the entire Chinese language just to say "hi". I honestly wasn't sure if I would find anything to help me with this problem. *a single tear*:p
All you guys rule!!!!
Thank you ALL so much. I can't thank you enough!
If you know anything else that is cool, please add it. This thread is still open. :D
jumpedintothefire
08-12-2003, 01:07 PM
Have a look at this thread:
http://www.justlinux.com/forum/showthread.php?s=&threadid=85478
mdwatts
08-12-2003, 05:09 PM
Originally posted by Sepero
!OMG mdwatts!! Did you write that just for me!?! That's so cool!! Can I license it under GPL for ya? :p
Especially for you and it only took me one or two minutes to write. ;)
Sepero
08-12-2003, 10:01 PM
Originally posted by jumpedintothefire
Have a look at this thread:
http://www.justlinux.com/forum/showthread.php?s=&threadid=85478 Awsome post!
Wow guys. Most of the regulars here know that I answer at least 10 times more questions than I ever ask. I don't think I have ever needed your help more than this time, and you all REALLY came through, BIG TIME!
Now if only I could return the favor... Do you guys accept cash? heheh :p
mdwatts
08-13-2003, 06:11 AM
Originally posted by Sepero
Do you guys accept cash? heheh :p
I do !!! Lots of it ??? :)
justlinux.com
Copyright 2007 Jupitermedia Corporation All Rights Reserved.