Search This Blog

Friday, September 15, 2023

How to Compile .vb Code

Ever needed to compile some .vb code? Here's how I did it today.



Given a text file called Helloworld.vb with the following content...

Imports System
Module HelloWorld
    Sub Main(args As String())
        Console.WriteLine("Hello World!")
    End Sub
End Module

You can create this file on any path you see fit with any editor Notepad, Notepad++, Atom, VSCode, pick one.  : ) 

For this example I'm using Visual Studio 2022, which look like this...

Visual Studio defaults to creating content in your %userprofile%\source\repos dir. On creating the VB Console project HelloWorld, it saved the source as %userprofile%\source\repos\HelloWorld\HelloWorld\HelloWorld.vb. 

Make sure the latest vbc.exe is on the path.
On My Windows 11 PC it existed in...
C:\Windows\Microsoft.NET\Framework64\v4.0.30319.

With Visual Studio Community Edition 2022, I found it located in C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\Roslyn.

Make sure to search and use the on you want to work with.


Start cmd

Issue commands to go to the directory with your source .vb file

>c:
>cd %userprofile%\source\repos\HelloWorld\HelloWorld
>dir

You directory may look like the following...
Visual Studio will also create other legacy elements for managing the code within its environment. For our purposes they are not needed and can be ignored.

Issue the follow commands

>vbc HelloWorld.vb

** Vbc (the older .Net version) will tell you that there is a better method to use called Roslyn which comes automatically with Visual Studio.   

 

If you are using the Roslyn vbc it will look like this...



 
 

>dir

There's our .exe file!   :)

Run HelloWorld

From the cmd prompt issue the command "helloworld"


It works!   : )

You now have a .exe you can use anywhere.
 





Friday, February 25, 2022

Sharepoint Redirect to Notes:// - Part II

 Back in Thursday, November 19, 2015, I showed a bit if html that can be used as a redirector for custom URL handlers. Since then Microsoft has hardened their products a bit and an extra step is needed.

Create the content as shown in Sharepoint Redirect to Notes://.

Save the file, with the content shown in the post, with the extension as .http

Test it by double click the file. IT should open a browser tab and automatically launch the application as expected.

Copy the .http file, then change the extension to .aspx.

You typically cannot test this until it's used from a Sharepoint site.

Save the file on your Sharepoint site.

Test this by clicking on the file you just saved, it should behave as the redirector and open your application.

Get the URL to the .aspx file.

Test this by trying the URL in the address bar of a new browser tab or window, it should behave as the redirector and open your application.

On the Sharepoint page, modify the link to use the working URL acquired in the last step.

Test this by lots of happy clicks!    : )




You're done! 



Saturday, January 15, 2022

MyCompany Certificate Organization

I use a fictitious company called MyCompany for use in some of the things I describe in my writing..

I had done this write up a long time ago and it's influence can be seen in many of my post. I had done this to describe the naming of elements in a Domino DB environment, but many of these ideas are transferable to other directory structures. I'm putting this here so that others can see it as a template for themselves and maybe build on it.

If you want to see where it's been used, search this blog on "MyCompany".


Naming Conventions

Site Names

As far as sites are concerned, admins and business leaders need to come to their own terms. Traditionally, we have stuck with three characters representing a local name, the business unit, and the larger geography they exist in. For example:

        BMO - Butler Manufacturing Ohio
        MRO – Marysville Research Ohio

 Servers Names

Roles

  • SuperHubs - manage the replication and mail transfer between regions.
  • Hubs - can replicate application and route mail.
  • Spokes - are typically more specialized and are broken down into Application, Mail, Dev, QA, and other..

 Naming

Regional admins work with sites admins to work out the names, but should be  named after their functions. The only part which there is a hard rule are for the first two parts of the name.

  • The first character describes the server as an H (hub) server or an S (spoke) server. Superhubs are designated by Z.
  • Next is the site name (like JMO, MMO, PMO).
  • Lastly, the site specific unique identifier.

 Here are a few examples:
        HRSM0001/SRV/NA/MyCompany    Hub for Rochester, MA
        SRSMM001/SRV/NA/MyCompany    Mail server for Rochester, MA
        SRSMA001/SRV/NA/MyCompany    Application server for Rochester, MA
        HAMA001/SRV/NA/MyCompany    Hub server for Aubrey, Arkansas
        STMTBS01/SRV/NA/MyCompany    BlackBerry server for Townsend, Tennessee
        HAMA003/SRV/AU/MyCompany    Hub server for Albany, Australia
        ZMMO003/SRV/NA/MyCompany    Superhub in Marysville, Ohio
        SMMOM023/SRV/NA/MyCompany    Mail server in Marysville, Ohio

 My Company in North America

         /MyCompany

A regional admin will be given the regional cert to manage the creation of sites, servers and people. Regional admins can give sites a cert to manage servers and people.

 This is how NA (North America) is set up...

         /NA/MyCompany

         People
                Sales
                        /RSM/NA/MyCompany (Rochester, MA)
                Manufacturing
                        /AMA/NA/MyCompany (Aubrey, Arkansas)
                        /TMT/NA/MyCompany (Townsend, Tennessee)
                        /BMO/NA/MyCompany (Butler, Ohio, USA)
                        /EMO/NA/MyCompany (Euclid, Ohio, USA)
                        /JMO/NA/MyCompany (Jamestown, Ohio, USA)
                        /MMO/NA/MyCompany (Marysville, Ohio, USA)
                        /PMO/NA/MyCompany (Paulding, Ohio, USA)
                        /YMO/NA/MyCompany (Youngstown, Ohio, USA)
                        /WMK/NA/MyCompany (Weskan, Kansas)
                        /UML/NA/MyCompany (Uncle Sam, Louisiana)
                R&D
                        /MRO/NA/MyCompany (Marysville, OH)
                Canada (Sales, Mfg.)
                        /CN/NA/MyCompany (York Point, Prince Edward Island)
                Mexico (Sales, Mfg.)
                        /MX/NA/MyCompany (Oaxaca, Oaxaca)
        Servers
                /SRV/NA/MyCompany

Other Certs

        AF (Africa)
                /KSS/AF/MyCompany (Koidu Town, Kono District, Sierra Leone)
        AN (Antartica)
                /HRS/AF/MyCompany (Husvik, South Georga Island)
        AS (Asia)
                /GMC/AF/MyCompany (Qingzhen, Guizhou, China)
                /HMC/AF/MyCompany (Dongfang, Hainan, China)
                /MMI/AF/MyCompany (Parbhani, Maharashtra, India)
        AU (Australia)
                /AMA/AF/MyCompany (Albany, Western Australia, Australia)
        EU (Europe)
                /BME/EU/MyCompany (Sutton , Central Bedfordshire, England)
        SA (South America)
                /AMA/EU/MyCompany (Albany, Western Australia, Australia)

Many of these sites also have Sales included on the same certs.
There are also research facilities in India (MRI) and in England (BRE).

 

You're done!






Monday, May 17, 2021

Powershell - Create New CentOS Workstation VM

 

I put this initial rundown together for further coding thingies, like state checking and condition handling. Simple enough, with room to grow.   : )

I did this using on Windows 10 pro, with Hyper-V, using Powershell 7 for a CentOS workstation.

The pile of code: https://github.com/LesleyPhillips/Build-CentOSWorkstation.ps1/blob/main/Build-CentOSWorkstation.ps1

Normally, I just throw up CentOS minimal builds. This time I thought I'd try something prettier.




Thursday, October 1, 2020

Windows 10 Firewall Ports

From time to time I have to open a port to do something and close it back up when I'm done. As I do this fairly often (but not often enough to memorize) I created this recipe. There is an example using Docker below.


ugh! an error! what to do?



Background Information...


How to do this by the Windows user Interface (UI)

https://www.google.com/search?q=windows+10+firewall+enable+localhost%3A80+traffic

How to do this with Powershell

https://www.google.com/search?q=powershell+TCP+Port+80+in+Windows+Firewall 

https://docs.microsoft.com/en-us/powershell/module/netsecurity/new-netfirewallrule?view=win10-ps

https://serverfault.com/questions/883266/powershell-how-open-a-windows-firewall-port


 

Powershell 


Open the port


New-NetFirewallRule -DisplayName "Allow inbound TCP port 81" -Direction inbound -LocalPort 81 -Protocol TCP -Action Allow
Name                  : {af16f2f3-3221-4191-8c5a-f44a5f60ca58}
DisplayName           : Allow inbound TCP port 81


Test (while something is listening on the port)


 Get-NetFirewallRule -Name '{af16f2f3-3221-4191-8c5a-f44a5f60ca58}'

    ** You can also see this in the Windows firewall inbound rules

$tcp = New-Object System.Net.Sockets.TcpClient
$tcp.Connect("localhost","81")
$tcp.Connected
True


Close the port back up


Remove-NetFirewallRule -Name '{af16f2f3-3221-4191-8c5a-f44a5f60ca58}'

** If you test again, you should get a failure (or, your listening port was not blocked already). And, the control panel, on refresh, will show the rule is missing.

You're done! 



Example


As a semi-practical example, Start a Docker container, test and clean up. For this to be a real example, you would have to imagine that port 81 was the blocked port. On port 80, I got stuff running there already. So, I did this on port 81.


Open the Port


New-NetFirewallRule -DisplayName "Allow inbound TCP port 81" -Direction inbound -LocalPort 81 -

Start the getting-started container


docker run -d -p 81:80 docker/getting-started
6d44c9240e688b69a212fe24e58d2302b658bfcbcee787030943b04f12cde38b

Test that the container is running and on the proper port.


docker ps
CONTAINER ID        IMAGE                    COMMAND                  CREATED             STATUS              PORTS                NAMES
6d44c9240e68        docker/getting-started   "/docker-entrypoint.…"   6 seconds ago       Up 4 seconds        0.0.0.0:81->80/tcp   goofy_elion

Test the port via Powershell


(New-Object System.Net.Sockets.TCPClient –Argument "localhost","81").Connected
True

Open page in local browser http://localhost:81

 

Hooray! It works!   : ) 


Clean up the container


docker stop 6d44c9240e68
6d44c9240e68

Remove the firewall rule by Powershell


Remove-NetFirewallRule -Name '{af16f2f3-3221-4191-8c5a-f44a5f60ca58}'



You're done again!




Thursday, September 10, 2020

SMTP Telnet

 I was working an issue with a Microsoft Edge Transport server where the content of the email was getting truncated after 6 lines. I was able to create a test and get show the delivery of the message through the Edge server to the destination mailboxes. But My test did not include the attached file of the messages that were failing. as the file was a really small csv I took up the challenge of generating the email with an attachment through a telnet session.

Steps: 

Get the csv attachment.

Generate the mime for the attachment

Modify the text of the telnet session to generate the message

Check the results.


I created a small csv using a text editor 

Company,Address,City,State,Zip

CareWorks Technologies,,Dublin,Ohio,43016

CTG,55 Public Square,Cleveland,Ohio,44113

"State Industrial Products, Inc.",3100 Hamilton Avenue,Cleveland,Ohio,44114

"Finast Supermarkets, Inc.",17000 Rockside Road,Maple Heights,Ohio,44137

Saved it as C:\Users\Lesley\Downloads\Companies.csv

Using Poswershell,

[Convert]::ToBase64String([IO.File]::ReadAllBytes('C:\Users\Lesley\Downloads\Companies.csv'))

I generated the following mime blob...
Q29tcGFueSxBZGRyZXNzLENpdHksU3RhdGUsWmlwDQpDYXJlV29ya3MgVGVjaG5vbG9naWVzLCxEdWJsaW4sT2hpbyw0MzAxNg0KQ1RHLDU1IFB1YmxpYyBTcXVhcmUsQ2xldmVsYW5kLE9oaW8sNDQx
MTMNCiJTdGF0ZSBJbmR1c3RyaWFsIFByb2R1Y3RzLCBJbmMuIiwzMTAwIEhhbWlsdG9uIEF2ZW51ZSxDbGV2ZWxhbmQsT2hpbyw0NDExNA0KIkZpbmFzdCBTdXBlcm1hcmtldHMsIEluYy4iLDE3MDAw
IFJvY2tzaWRlIFJvYWQsTWFwbGUgSGVpZ2h0cyxPaGlvLDQ0MTM3DQo=
I then added that to a telnet session like this...
telnet 10.0.0.10 25
HELO lesley.mycompany.com
MAIL FROM: <lesley@mycompany.com>
RCPT To: <lesleyphillips@yahoo.com>
DATA
subject: TLX21MLC1 : PCC LOADER JOB COMPLETED
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary=border
--border
Content-Type: text/plain
 
A short list of companies I've worked at

-Lesley

--border
Content-Type: application/octet-stream
Content-Transfer-Encoding: base64;
Content-Disposition: attachment;
        filename="Companies.CSV"

Q29tcGFueSxBZGRyZXNzLENpdHksU3RhdGUsWmlwDQpDYXJlV29ya3MgVGVjaG5vbG9naWVzLCxEdWJsaW4sT2hpbyw0MzAxNg0KQ1RHLDU1IFB1YmxpYyBTcXVhcmUsQ2xldmVsYW5kLE9oaW8sNDQx
MTMNCiJTdGF0ZSBJbmR1c3RyaWFsIFByb2R1Y3RzLCBJbmMuIiwzMTAwIEhhbWlsdG9uIEF2ZW51ZSxDbGV2ZWxhbmQsT2hpbyw0NDExNA0KIkZpbmFzdCBTdXBlcm1hcmtldHMsIEluYy4iLDE3MDAw
IFJvY2tzaWRlIFJvYWQsTWFwbGUgSGVpZ2h0cyxPaGlvLDQ0MTM3DQo=
--border--
 
.
 
quit

And, the result...




Friday, July 24, 2020

Python - Has Your Password Been Pwned?

I was reading the Spring 2020 edition of 2600 and ran into this little article on page 18, titled "Has Your Password Been Pwned?" by Jan Markowski. It was originally written in Bash so I used it as a little exercise for Python.


#!/usr/bin/python

#
# Has Your Password Been Pwned?
# This code is based on published code published in 2600, Spring 2020, page 18
# by Jan Markowski, livetrue@pm.me
#


import getpass
import hashlib
import re
import sys
import urllib.request

def Check_PW_Pwanage(password):

    fGotAPassword = False
    try:
        PW_hash = hashlib.sha1(password)
        PW_hash_digest = PW_hash.hexdigest()
        PW_hash_digest_a = PW_hash_digest[0:5].upper()
        PW_hash_digest_b = PW_hash_digest[5:40].upper()
        fGotAPassword = True
    except:
        e = sys.exc_info()[0]
        print("Error: %s" % e)

    PW_occurances = 0

    if fGotAPassword == True:
        try:
            with urllib.request.urlopen("https://api.pwnedpasswords.com/range/%s" % PW_hash_digest_a) as response:
                sh1_res = response.read().decode()
            sh1_res_lines = sh1_res.split('\r\n')
            print("pwnedpasswords.com returned %s lines matching the beginning of your hash." % len(sh1_res_lines))
            regex = re.compile('^'+PW_hash_digest_b)
            idxs = [i for i, item in enumerate(sh1_res_lines) if re.search(regex, item)]
            sh1_res_line = sh1_res_lines[idxs[0]]
            PW_occurances = sh1_res_line[sh1_res_line.rfind(':')+1:]
        except:
            pass

    return PW_occurances
      
       
       
def main():
    password = getpass.getpass("Type your password and press enter: ")
    ret = int(Check_PW_Pwanage(password.encode()))
    if ret > 0:
        print('Your password has been pwned %s times!' % ret)
    else:
        print ('but, none of them matched your full hash.')
        print('Your Password is safe!')


if __name__ == "__main__": main()






Here is what it looks like when you run it...

This examples is using the password of '12345'.


And, when you use a password 'R\Ts)-f]'



Here's what is happening...

Putting in the password of '12345' generates the following hash...
'8CB2237D0679CA88DB6464EAC60DA96345513964'

Breaking that in to two parts get me a query part: '8CB22'
And, a search part: '37D0679CA88DB6464EAC60DA96345513964'

I get the results from https://api.pwnedpasswords.com/range/8cb22  (notice the query part at the end) and scan for the search part which points me to line 121. You should go to that page and look at the results.
'37D0679CA88DB6464EAC60DA96345513964:2389787'
From which I get the number of hits at the end as: 2389787



The front end of the pwned passwords web site is: https://haveibeenpwned.com/Passwords

If you are looking for good passwords, try the folks at Gibson Research. They have some good information on what makes a good password.

Lastly, 2600 is available at https://2600.com