Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
1.44/5 (2 votes)
See more:
i wont to convert this script to c# ,any Professional coder can help me !
#Grab the attacker's IP address from the alert file
sub get_alert_ip{
open (ALERT, "alert.ids") or die "Cannot open or read alert file";

while (<alert>)
{
next if (/^\s*$/); #skip blank lines
next if (/^#/); # skip comment lines
if (/\.*\s(\d+\.\d+\.\d+\.\d+)\.*/) #Grab the IP Address
{
$alertip=$1;
print "Alert IP address is $alertip \n";
}
}
close (ALERT);
#Check to see if you got it!
if ($ip eq ""){ print "Could not get the IP address out of the alert
file! \n";}
$alertip;
}
#########
#Compares the new IP address to the IP address I have already
captured
sub compare_ip{
my ($compareip) = @_;
open (COMPARE, "attackers.old") or die "Cannot read the ignore file,
$!\n";
while (<compare>) {
chop;
next if (/^\s*$/); #skip blank lines
next if (/^#/); # skip comment lines
if (/(.*)/)
{
}
}
$alertip=$1;
if ("$alertip" eq "$compareip")
{
print "Somebody old is still attacking \n";
}
else
{ #Send the new IP address to the IPSEC filter subfunction
&ipfilter($compareip);
$tag=1;
}
next;
close (COMPARE);
if ($tag eq 1)
{
system ("echo $compareip >> attackers.old");
}
}
Posted
Updated 24-Sep-12 23:36pm
v2
Comments
Kuthuparakkal 25-Sep-12 4:59am    
what have you tried so far ? We can help but dont expect us to write code for you!
Zoltán Zörgő 25-Sep-12 4:59am    
It would be better to write the specification implemented by this code - and rewrite it from scratch in c#. "Converting" has no meaning is this sense.

Perl is a write once and don't dare to touch again scripting language. Even at it's best it can be hard to understand.

what you can do is extract the notion of what the perl script is doing and implement it as best you can in c#.
 
Share this answer
 
sub new
{
my $proto = shift;
my $class = ref($proto) || $proto;

my $self = {};
bless($self, $class);

# Run initialisation code
$self->_init(@_);

return $self;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900