summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinuxWizard42 <linuxwizard@voidnet.dy.fi>2023-03-15 19:46:22 +0200
committerLinuxWizard42 <linuxwizard@voidnet.dy.fi>2023-03-15 19:46:22 +0200
commit171952a5b70c00b676fe425b4187dbc8832313da (patch)
tree56cb279e246ce8b7c2e85b903030b7542e10a69f
downloadUsernameGenerator-171952a5b70c00b676fe425b4187dbc8832313da.tar.gz
UsernameGenerator-171952a5b70c00b676fe425b4187dbc8832313da.tar.zst
First commitHEADmaster
-rwxr-xr-xusernamegenerator.pl47
1 files changed, 47 insertions, 0 deletions
diff --git a/usernamegenerator.pl b/usernamegenerator.pl
new file mode 100755
index 0000000..ea03305
--- /dev/null
+++ b/usernamegenerator.pl
@@ -0,0 +1,47 @@
+#!/usr/bin/perl
+
+#######################################################
+# Username generator using username-generator.com API #
+#######################################################
+
+use IO::Socket;
+use IO::Socket::SSL;
+use HTTP::Tiny;
+use JSON::PP;
+
+if ( defined($ARGV[0]) and scalar(@ARGV) > 0 ){
+ if ( $ARGV[0] eq "" or length($ARGV[0]) <= 0 or int($ARGV[0]) <= 0 ){
+ die "Error: non-valid amount of usernames given";
+ }
+ print( "Getting usernames..\n" );
+ my $hc = HTTP::Tiny->new(
+ "agent" => "UsernameGenerator"
+ ) or die "Error: failed to initialize https";
+ my $hreq = $hc->request( "GET", "https://www.username-generator.com/usernames_json?num_results=".$ARGV[0], {
+ "headers" => {
+ "Accept" => "*/*"
+ }
+ } ) or die "Error: https request failed";
+ if ( $hreq->{"success"} ){
+ my $res_parsed = JSON::PP->new->utf8->pretty->decode($hreq->{"content"}) or die "Error: failed to parse response";
+ my $names = int(scalar(@{$res_parsed->{"usernames"}}));
+ for ( my $ucount = 0; $ucount < $names; $ucount++ ){
+ print( $res_parsed->{"usernames"}->[$ucount] . "\n" );
+ }
+ if ( defined($ucount) ){
+ undef $ucount;
+ }
+ undef $names;
+ undef $res_parsed;
+ }
+ else
+ {
+ print( "Error: HTTPS request failed (" . $hreq->{"status"} . ": " . $hreq->{"reason"} . ")\n" );
+ }
+ undef $hreq;
+ undef $hc;
+}
+else
+{
+ die "Error: number of usernames not given";
+} \ No newline at end of file