-2

Can anyone provide me with a c# regex for tapping an elastic ip in the request url? Sometimes we get some strange requests with the elastic ip of our servers/load balancer within the url's. I need to put dumb redirects to my original domains/stop processing such requests.

EDIT: By elastic ip I mean, the ec2 ip for server's on amazon cloud. It has this pattern for the hostname. ec2-11-111-222-333.cd-blahblah-1.compute.amazonaws.com

Siva Bathula
  • 746
  • 1
  • 8
  • 19
  • You should really let us know what you've tried first. Check out: http://whathaveyoutried.com - it's a great guide on how to formulate a good question. – FrankieTheKneeMan Apr 03 '13 at 22:26
  • @FrankieTheKneeMan - I think my questions stands for itself. ec2 url's are somewhat different in that, they have a strange enough pattern. ec2-123-45-67-890-th-computezone-blahblah.aws.com. I admit I am not an expert at writing Regex, but this question deserves an answer. The question is quite simple, look for ec2's pattern of domain host within the url using regex and tap such requests, to put some redirect rules on top of it. Now the redirection part is fairly simple can be done in several ways, which I dont need help for. Just a regex pattern using which I can find out if it is an ec2 url. – Siva Bathula Apr 05 '13 at 18:28
  • @FrankieTheKneeMan To answer to your question, I haven't tried much as I dont know how to write slightly complicated regex's like this one. I thought I might find some help in this community. In any case, its not your regular ip in the host-name as I pointed in my previous comment. If it was I would have taken it from various suggestions from StackOverflow itself. – Siva Bathula Apr 05 '13 at 18:39
  • Siva, the point I was making is that Stack Overflow is not here to simply do your work for you. Check out the on-site guide for writing a good question: http://stackoverflow.com/questions/how-to-ask. Doing better research before coming here is a part of the social contract we as a community all must subscribe to in order to keep people from abusing the site as a code for hire substitute. No matter how wrong your previous attempts, you should at least try something. If you need a guide on regular expressions, check out http://www.regular-expressions.info/tutorial.html – FrankieTheKneeMan Apr 06 '13 at 00:14
  • Also, IP addresses are strictly numeric. You're talking about Hostnames. – FrankieTheKneeMan Apr 06 '13 at 00:16
  • @FrankieTheKneeMan - Thanks for the information. I generally put a lot of research, but this is one area(regex) which I am really bad at, so was dying to ask this. Anyways, the ec2-hostname pattern contains an ip with the dot replaced by a hyphen, sorry if it was misleading. – Siva Bathula Apr 07 '13 at 05:37

1 Answers1

2

It seems to me you could probably just check if the compute.amazonaws.com part is in the string, but in case that is not enough (some legitimate traffic from those hosts), you may be able to use this (the example is not that full, there might be cases this does not catch)

ec2-[0-9-]+.cd-[a-z0-9-]+.compute.amazonaws.com
carlpett
  • 12,203
  • 5
  • 48
  • 82